hoe在输入数据时更改文本框中文本的颜色 [英] hoe to change color of text in text box while entering data
本文介绍了hoe在输入数据时更改文本框中文本的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用asp.net c#。
我有一个输入用户名的文本框。
我需要的是当页面加载时,此文本框应该带有灰色的数据用户名,当用户点击文本框中的用户名时文本应该消失。
当用户在里面输入任何内容时,文字颜色应该从灰色变为黑色。
我使用下面的代码。但颜色如何改变?
I am working with asp.net c#.
I have a text box for entering user name .
What i need is when the page load , this text box should carry the data 'username ' in ash colour and when user click on the text box the 'username' text should disappear .
when user types anything inside , the color of text should change to black from ash.
I used the below code. but color how to change?
<asp:TextBox ID="txtContact" runat="server" ForeColor="#999999" value="Contact Number" onfocus="if (this.value == 'Contact Number') {this.value = '';}"
onblur="if(this.value == '') { this.value='Contact Number';}"
Width="251px"></asp:TextBox>
推荐答案
更改你的onfocus evetn到这个
change your onfocus evetn to this
onfocus="if (this.value == 'Contact Number') {this.value = ''; this.style.color = '#000000';}"
这篇关于hoe在输入数据时更改文本框中文本的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文