【发布时间】:2013-09-30 14:29:05
【问题描述】:
这是一个文本框:
<asp:TextBox ID="UsernameTextBox" runat="server" class="BlockInput"></asp:TextBox>
我想给 asp textbox 一些颜色,但它不会改变颜色
<script type="text/javascript">
function BlockInput() {
var elements = document.getElementsByClassName("BlockInput");
for (var i = 0; i < elements.length; i++) {
elements[i].readOnly = true; // works
elements[i].style.color = "#000000";// does not work!
}
}
window.onload = BlockInput;
</script>
当我查看源代码时,我可以看到正在添加的样式:
<input name="ctl00$MainContent$UsernameTextBox"
type="text" id="MainContent_UsernameTextBox"
class="BlockInput" readonly="" style="color: rgb(0, 0, 0);">
我还确保没有任何内容覆盖 css。
【问题讨论】:
-
你是指面色还是背景色?
-
关于最佳实践的评论:stackoverflow.com/questions/559150/…
-
是的,伙计们,我正在尝试改变背景
标签: javascript html asp.net css