Home >Web Front-end >JS Tutorial >Share the solution to the problem that jquery blur does not trigger
The code is as follows
$("#username").blur(function(){ alert("ass");//鼠标点击Blur 按tab键在第一次的时候没有触发 $.getJSON("send.php?action=get_&n="+Math.random(),function(data) { if (data.res!=="none"){ setTimeout("$('#gb_tip_layer').hide('100');",5000); } }); }); <input name="username" type="text" class="text-input" id="username"/>
The effect I want to achieve is to trigger a request when the username text box is blurredQuery. But the problem is, whether the mouse clicks elsewhere on the page or presses the TAB key to go to the next form item, the function bound to the blur event will not be triggered. Blur will only be triggered when clicked again. What is the situation? How to solve it? Thank you!
blur is triggered by the focus of the event. It is triggered as long as the cursor leaves the username text field.
The blur event first needs to be focused on this control. When this It will only be triggered when the control loses focus. I wonder how the original poster understands this event?
You first remove the paragraph
$.getJSON("send.php?action=get_&n="+Math.random(),function(data) { if (data.res!=="none"){ setTimeout("$('#gb_tip_layer').hide('100');",5000); } });
and try to see if the function works properly.
What I want is that when the username is entered, When the focus moves to the next text box, a function is triggered to detect whether the data in username exists. . .
What’s depressing is that the first blur did not trigger the binding function, and it only had an effect when the second blur was used.....
$("document").ready(function validate(){ }
The code can be placed in ready.
Forgot to explain, $("#username") is placed in the div pop-up layer, use $("document").ready(function validate(){ }
Can't find it.
The above is the detailed content of Share the solution to the problem that jquery blur does not trigger. For more information, please follow other related articles on the PHP Chinese website!