For example:
Search box: <input value = "Search for products..."/>
Text area: You can <textarea> enter your suggestions or comments to create more convenient services for your website... </textarea>
........
First of all, this kind of prompt function is very good and intuitive, but how to clear the content when they get the focus, if the content is empty after the focus is lost, the prompt text will be displayed .....
How to manage the page when there are more elements...
Copy codeThe Code is as follows:
Var inputText = function (o, e, e2 ){
If (! O) return; var txt = o. value;
Function inputTextChange (o, e, e2, txt ){
O [e] = function () {var txt2 = o. value; if (txt = txt2) o. value = ""}
O [e2] = function () {var txt2 = o. value; if (txt2 = "") o. value = txt}
}
New inputTextChange (o, e, e2, txt)
}
I defined a function above.
Function Description:
Parameter [o]: object to be operated
Parameter [e]: event for which the object value needs to be cleared
Parameter [e2]: event to return the default value
Function call:
InputText (userName, "onmouseover", "onmouseout ");
Function Application Example:
Copy codeThe Code is as follows:
<Html> <Title> input. value </title>
</Head> <body>
<Script>
Var inputText = function (o, e, e2) {if (! O) return; var txt = o. value;
Function inputTextChange (o, e, e2, txt ){
O [e] = function () {var txt2 = o. value; if (txt = txt2) o. value = ""}
O [e2] = function () {var txt2 = o. value; if (txt2 = "") o. value = txt }}
New inputTextChange (o, e, e2, txt)
}
</Script>
<Input type = "text" value = "Enter your email address..." on/>
<Input type = "text" value = "enter your home address..."/>
<Input type = "text" value = "Enter your mobile phone number..."/>
<Script>
Var inputArr = document. getElementsByTagName ("input ")
For (var I in inputArr ){
If (! InputArr [I]. type = "text") continue;
InputText (inputArr [I], "onfocus", "onblur ")
}
</Script>
</Body>