Jquery CCS在聚焦/模糊时改变前向颜色

Jquery CCS在聚焦/模糊时改变前向颜色,jquery,css,Jquery,Css,我的代码: <asp:TextBox ID="TOTAL" onfocus="if (this.value == this.defaultValue) { this.value = ''; this.ForeColor = black; }" onblur="if (this.value == '') this.value = this.defaultValue; this.css('color', 'LightGray');" style="text-align: center;

我的代码:

<asp:TextBox ID="TOTAL" 
onfocus="if (this.value == this.defaultValue) { this.value = '';  this.ForeColor = black; }"
onblur="if (this.value == '')  this.value = this.defaultValue; this.css('color', 'LightGray');" 
style="text-align: center;" runat="server" Height="16px" Width="60px" ForeColor="LightGray">8</asp:TextBox>

不起作用,我不想使用jQ,比如:

$('input').focus(function(){
 if($(this).val() == this.defaultValue){$(this).val('');$(this).css("color","green");}
}).blur(function(){
 if($(this).val() == ''){$(this).val(this.defaultValue);$(this).css("color","grey");}
});

尝试使用
此.style.color


不确定它是否能跨浏览器/跨(旧)版本工作,这通常是jQuery为您解决的问题,但您显然反对这一点…

@Peter B谢谢您,正在工作;)

解决方案:

<asp:TextBox ID="TOTAL" onfocus="if (this.value == this.defaultValue) { this.value = ''; this.style.color = 'black'; }"
         onblur="if (this.value == '' || this.value == this.defaultValue) { this.value = this.defaultValue; this.style.color = 'LightGray'; }" style="text-align: center;" runat="server" Height="16px" Width="60px" ForeColor="LightGray">8</asp:TextBox>
8
this.ForeColor = 'black'
$('input').focus(function(){
 if($(this).val() == this.defaultValue){$(this).val('');$(this).css("color","green");}
}).blur(function(){
 if($(this).val() == ''){$(this).val(this.defaultValue);$(this).css("color","grey");}
});
.classname{color:grey}
.classname:focus, .clasname:active { color:green}
<asp:TextBox ID="TOTAL" onfocus="if (this.value == this.defaultValue) { this.value = ''; this.style.color = 'black'; }"
         onblur="if (this.value == '' || this.value == this.defaultValue) { this.value = this.defaultValue; this.style.color = 'LightGray'; }" style="text-align: center;" runat="server" Height="16px" Width="60px" ForeColor="LightGray">8</asp:TextBox>