Click the text box to clear the default text to leave and then restore:
Many web sites need to fill in the text box in the default state will give a default prompt language, when the mouse click on this text box can be the default text inside clear, when the input text is deleted and the focus away from the text box when the default text is written to the text box.
The code is as follows:
<!DOCTYPE HTML><HTML><Head><MetaCharSet= "Utf-8"><Metaname= "Author"content= "http://www.softwhy.com/" /><title>Click the text box to clear the default values-ant tribe</title><Scripttype= "Text/javascript">window.onload=function(){ varusername=document.getElementById ("username"); Username.onclick=function() { if(Username.value=="Please enter your name") {Username.value=""; This. focus (); }} Username.onblur=function() { if(Username.value=="") {Username.value="Please enter your name"; } }}</Script></Head><Body><inputtype= "text"value= "Please enter your name"ID= "username" /></Body></HTML>
The above code to achieve our requirements, when clicking on the text box can clear the text box content, if the text box does not enter any content, this time when the mouse focus away from the text box, the value of the text box will be restored to the default state. However, if the password box Ken is a bit troublesome because the password box is not displayed in clear text, the solution can see How to Implement the Password box in the prompt section.
Related reading:
1.onclick events can be found in the OnClick events section of JavaScript .
The 2.onblur event can be found in the Onblur event section of JavaScript .
The original address is: http://www.softwhy.com/forum.php?mod=viewthread&tid=9421
For more information, refer to: http://www.softwhy.com/javascript/
Click the text box to clear the default text left and then restore