In network applications, we sometimes need to remind users to enter the value of the text box. To ensure the correctness of user input, we can use JavaScript to solve this problem. For example, you need to enter a nickname:
<Input type = "text" name = "inpname" id = "inpname" class = "text" size = "28" tabindex = "1"/> <label for = "inpname "> name (*) </label> </P>
Sometimes, some users forget to enter the information temporarily. When the value of the text box is empty, we will continue to prompt. To ensure the validity of user input!
Insert the code into: value = "Enter your nickname... "onfocus =" If (value = 'enter your nickname... ') {value = ''}" onblur = "If (value ='') {value =' enter your nickname... '}"
Final effect: <input type = "text" name = "inpname" id = "inpname" class = "text" size = "28" tabindex = "1" value = "Enter your nickname... "onfocus =" If (value = 'enter your nickname... ') {value = ''}" onblur = "If (value ='') {value =' enter your nickname... '} "/> <label for =" inpname "> name (*) </label>
--------------------------------------------------------
<SCRIPT>
Function onenter (field) {If (field. value = field. defaultvalue) {field. value = "";}}
Function onexit (field) {If (field. value = "") {field. value = field. defaultvalue ;}}
</SCRIPT>
<Input type = text value = "default text" onfocus = onenter (this) onblur = onexit (this)>