First of all, JavaScript is written directly on the input
Copy Code code as follows:
<input name= "Pwuser" type= "text" id= "Pwuser" class= "input" value= "real Estate account" onblur= "if (this.value== ') this.value= ' Real estate account '; "onfocus=" if (this.value== ' real estate account ') this.value= '; "/>
<input name= "pwpwd" type= "password" class= "input1" "value=" "Hu" "onblur=" if (this.value== ') this.value= ' Hu Jintao '; Onfocus= "if (this.value== ') this.value= ';" >
jquery Implementation Method
For the element focus event, we can use the focus function of jquery (), Blur ().
Focus (): used in the same way as onfocus in JavaScript, when it is focused.
Such as:
Copy Code code as follows:
$ ("P"). focus (); or $ ("P"). Focus (FN)
Blur (): Use when losing focus, same as onblur.
Such as:
Copy Code code as follows:
$ ("P"). blur (); or $ ("P"). blur (FN)
Instance
Copy Code code as follows:
<form>
<label for= "Searchkey" id= "Lbsearch" > Search god Horse? </label> here the label is overlaid on the text box to better control the style
<input id= "Searchkey" type= "text"/>
<input type= "Submit" value= "Search"/>
</form>
jquery Code
Copy Code code as follows:
$ (function () {
$ (' #searchKey '). focus (function () {
$ (' #lbSearch '). Text (');
});
$ (' #searchKey '). blur (function () {
var str = $ (this). Val ();
str = $.trim (str);
if (str = = ")
$ (' #lbSearch '). Text (' Search God horse? ');
});
})
Well, that's pretty good.