我已在我的 aspx 页面中声明了 asp:textbox。
<asp:TextBox ID="txta" runat="server" size="12" value="123"></asp:TextBox>
我在 HEADER 中有一个 javascript 函数:
<head runat="server">
<title>My Page</title>
<script type = "text/javascript" >
function changeColor() {
document.getElementById('<%= txta.ClientID %>').backgroundColor="#FF0000";
alert( '<%= txta.ClientID %>');
}
</script>
</head>
在 Page_Load 事件中,我将 onBlur 属性与 asp 控件一起加入,如下所示:
txta.Attributes.Add("onblur", "changeColor();")
当控件失去焦点时,会显示警报,但背景颜色不会改变。
如何实现这一目标?
最佳答案
使用document.getElementById('<%= txta.ClientID %>').style.backgroundColor = "#FF0000";
.
您忘记了.style
.
关于javascript - 更改 ASP 的背景颜色 :TEXTBOX via javascript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38791568/