2012-07-17 90 views
1

我有一个文本在我的表格中提交。文本字段中文本的颜色应为灰色。如果我点击它并键入,文本应该变黑,并保持黑色。文本字段输入颜色css

我用下面的CSS。

input[type=text]{ color:#999999;} 
input[type=text]:focus{ color:#000;} 

这是我的html代码

<input name="address" id="address" type="text" onFocus="if(this.value =='Address') this.value=''" onBlur="if(this.value=='') this.value='Address'" value="Address"> 

现在的文字变成黑色的颜色,当我打字。但输入后会变回灰色。打字后我需要黑色。我怎样才能做到这一点?

+0

所以你的意思是你不想改变y的颜色我们的文字在输入时和输入正确后? – Kishore 2012-07-17 04:46:24

+2

为什么你不能在输入字段中使用'placeholder'属性? – 2012-07-17 04:48:59

回答

3

如何

<input name="address" id="address" type="text" 
     onFocus="if(this.value =='Address')this.value='';this.style.color='#000';" 
     onBlur="if(this.value=='') this.value='Address'; if (this.value=='Address') this.style.color='#999';" 
     value="Address"> 
+0

它的工作。非常感谢。 – designersvsoft 2012-07-17 05:15:38

+0

嗨,还有一个帮助。如果我点击重置按钮输入文本应该再次变成灰色。任何建议? – designersvsoft 2012-07-17 10:00:05

0

不知道你的问题是100%清楚,但你为什么不只是扭转你的CSS值是多少?

<style> 
input[type=text]{ color:#000;} 
input[type=text]:focus{ color:#999999;} 
</style> 

<p> 
<input name="address" id="address" type="text" onFocus="if(this.value =='Address') this.value=''" onBlur="if(this.value=='') this.value='Address'" value="Address"> 
</p> 

有了这个文本是黑色和焦点它是灰色的但聚焦后它回到黑色。

0

对于以上问题,看看,请在下面写HTML:

<input name="address" id="address" type="text" onFocus="if(this.value =='Address') this.value=''" onBlur="if(this.value==''){ this.value='Address'; } else{ this.style.color='#000'; }" value="Address"> 

CSS,因为它是:

input[type=text]{ 
    color:#999999; 
} 
input[type=text]:focus{ 
    color:#000; 
} 

,如果你想测试你的箱子然后http://codebins.com/bin/4ldqpaq