Home >Web Front-end >JS Tutorial >About the operation js code of text box default value_javascript skills

About the operation js code of text box default value_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:57:28965browse

For example:
Search box: you can
Text area: you can
.....
First of all, this kind of prompt function is very good and very intuitive, but how to make the content clear when they gain focus? After losing focus, if the content becomes empty, the prompt text will be displayed...
How to manage when there are too many elements on the page... and other questions

Copy code The 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 explanation:
Parameter [o]: The object that needs to be operated
Parameter [e]: The object that needs to be cleared Value event
parameter [e2]: event that needs to return the default value
function call:
inputText (userName, "onmouseover", "onmouseout");
function application example:
Copy code The code is as follows:


input.value

< ;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)
}