First of all, JavaScript is written directly on the input
The code is as follows |
Copy Code |
<input name= "Pwuser" type= "text" id= "Pwuser" class= "input" value= "real Estate account" onblur= "if (this.value== ') this.value= ' real estate Account Number '; "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:
The code is as follows |
Copy Code |
$ ("P"). focus (); or $ ("P"). Focus (FN) |
Blur (): Use when losing focus, same as onblur.
Such as:
The code is as follows |
Copy Code |
$ ("P"). blur (); or $ ("P"). blur (FN) |
Instance
The code is as follows |
Copy Code |
<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
The code is as follows |
Copy Code |
$ (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.