<asp:TextBox ReadOnly="true" ID="tbPhone" ClientIDMode="Static" runat="server" CssClass="tbStyle changeUpdate" Text=""></asp:TextBox>
<asp:TextBox ReadOnly="true" ID="tbFax" ClientIDMode="Static" runat="server" CssClass="tbStyle changeUpdate" Text=""></asp:TextBox>
$('#tbPhone, #tbFax').keypress(function() { //works
this.style.backgroundColor = "#BCFFB9";
});
我将有很多文本框,并希望为每个文本框使用类,获取ID并设置背景颜色。这将确保我可以为所有文本框使用几行代码,而不管数字是多少。如何更改背景颜色使用一个类来定位控件的ID
所以我想这:
$(".changeUpdate").keypress(function() {
$(this).attr("id").style.backgroundColor = "#BCFFB9";
});
但我不断收到此错误:
0x800a138f - Microsoft JScript runtime error: Unable to set value of the property 'backgroundColor': object is null or undefined
我怎样才能解决我的问题。
谢谢你的纠正。我知道我错过了一些东西。 – Si8