Let's look at the javascript directly written on the input.
Copy codeThe Code is 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 = "******" onBlur = "if (this. value = '') this. value = '******'; "onFocus =" if (this. value = '*******') this. value = '';">
Jquery Implementation Method
For element focus events, we can use jQuery's focus functions focus () and blur ().
Focus (): used to obtain the focus, which is the same as onfocus in javascript.
For example:
Copy codeThe Code is as follows:
$ ("P"). focus (); or $ ("p"). focus (fn)
Blur (): used when the focus is lost, just like onblur.
For example:
Copy codeThe Code is as follows:
$ ("P"). blur (); or $ ("p"). blur (fn)
Instance
Copy codeThe Code is as follows:
<Form>
<Label for = "searchKey" id = "lbSearch"> Search Shenma? </Label> here, the label overwrites the text box to better control the style.
<Input id = "searchKey" type = "text"/>
<Input type = "submit" value = "Search"/>
</Form>
Jquery code
Copy codeThe Code is 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? ');
});
})
Okay, pretty good.