This article introduces two methods and one is to use javascriptonFocusonBlur to determine the focus and the loss of the focus, and the other is to use jquery $ (& quot; p & quot ;). blur (); or $ (& quot; p & quot ;). blur (fn) is implemented. If you need it, you can refer to the javascript directly written on the input.
The Code is as follows:
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:
The Code is as follows:
$ ("P"). focus (); or $ ("p"). focus (fn)
Blur (): used when the focus is lost, just like onblur.
For example:
The Code is as follows:
$ ("P"). blur (); or $ ("p"). blur (fn)
Instance
The Code is as follows:
Jquery code
The 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.