<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