CCS改变了前焦距/ onblur

时间:2016-03-23 13:17:04

标签: 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;" runat="server" Height="16px" Width="60px" ForeColor="LightGray">8</asp:TextBox>

我正在尝试:

this.css('color', 'LightGray')

this.ForeColor = black

this.ForeColor = 'black'

不起作用,我不想使用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");}
});

3 个答案:

答案 0 :(得分:0)

.classname{color:grey}
.classname:focus, .clasname:active { color:green}

答案 1 :(得分:0)

尝试使用this.style.color

不确定它是否可以跨浏览器/跨(旧)-version工作,这是jQuery一般为您解决的问题,但显然您反对...

答案 2 :(得分:0)

@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>
相关问题