<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";
});
Run Code Online (Sandbox Code Playgroud)
我将有很多文本框,并希望为每个文本框使用一个类,获取ID并设置背景颜色.这将确保我可以为所有文本框使用几行代码,无论数字如何.
所以我试过这个:
$(".changeUpdate").keypress(function() {
$(this).attr("id").style.backgroundColor = "#BCFFB9";
});
Run Code Online (Sandbox Code Playgroud)
但我一直收到这个错误:
0x800a138f - Microsoft JScript runtime error: Unable to set value of the property 'backgroundColor': object is null or undefined
Run Code Online (Sandbox Code Playgroud)
我该如何解决我的问题.
小智 5
你有点混合Javascript和jQuery语法,试试这个:
$(".changeUpdate").keypress(function() {
//$(this).attr("id").style.backgroundColor = "#BCFFB9";
$(this).css("background-color","#BCFFB9");
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
664 次 |
| 最近记录: |