In the past, when we wrote various input events in js, we would write them directly in the input. Yesterday, I started to fully use jquery. Now let’s talk about my study notes on the jquery blur() focus() event.
For the focus event of the element, we can use jQuery's focusfunctionfocus(), blur().
focus(): Used when focus is obtained, the same asonfocusinjavascript.
Such as:
$("p").focus(); 或$("p").focus(fn)
Such as: blur(): used when the focus is lost, the same as onblur.
$("p").blur(); 或$("p").blur(fn)
Example
When the mouse is clicked in the search box, the text inside disappears.
An ajax value to determine whether to show or hide p
js $(function(){ $('#tgmo').blur(function(){ $.post('post.php?action=check',{'tgmo':$('tgmo').val()},function(data) { if( data==0 ) { $('#sy_a').show(); $('#autoregister').val(1); } else { $('#sy_a').hide(); $('#autoregister').val(0); } }); }) }); * 手机: 用房乐网会员登录名可获取5房乐币
The above is the detailed content of blur() loses focus and focus() gets focus event in jquery. For more information, please follow other related articles on the PHP Chinese website!