The code is as follows:
<asp:textbox id= "TextBox1" runat= "Server" height= "26px" maxlength= "ten" width= "166px" text= "Please enter user name" onfocus= " Javascript:if (this.value== ' Please enter user name ') {this.value= '; this.style.color= ' #000000 '} ' onblur= ' Javascript:if (this.value = = ') {this.value= ' Please enter user name '; this.style.color= ' #808080 '} ' forecolor= ' #808080 > </asp:TextBox>
Analytical:
1 · What the text box displays when the page loads
2 • After the text box triggers the focus, empty the text in the box and change the font color (you can also add formatting)
3 • After the focus leaves, determine if there is content in the text box, and no content restores the original font and formatting
4 · The color of the font in the text box when the page loads
Password Box code:
<asp:textbox id= "TextBox2" runat= "Server" height= "26px" width= "166px" text= "only a combination of numbers or letters" onfocus= "Javascript:if" ( this.value== ' Only a combination of numbers or letters ') {this.value= '; this.style.color= ' #000000 '; this.type= ' password '} "onblur=" Javascript:if (this.value== ") {this.type = ' text '; this.value= ' is only a combination of numbers or letters '; This.style.color= ' #808080 '} "forecolor=" #808080 "></asp:textbox >
Asp. NET text disappears when text box (Texbox control) has text in focus when page loads