如何以编程方式更改div的样式 [英] How do you change the style of a div programmatically

查看:70
本文介绍了如何以编程方式更改div的样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何更改div的样式(颜色),如下所示?

How do I change the style (color) of a div such as the following?

"<div id=foo class="ed" style="display: <%= ((foo.isTrue) ? string.Empty : "none") %>">
                        <%= ((foo.isTrue) ? foo.Name: "false foo") %>"`

推荐答案

如果要使用浏览器中运行的客户端代码(javascript)更改div的颜色,请执行以下操作:

If you want to alter the color of the div with client side code (javascript) running in the browser, you do something like the following:

<script>
 var fooElement = document.getElementById("foo");
 fooElement.style.color = "red"; //to change the font color
</script>

这篇关于如何以编程方式更改div的样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆