假设我要用blur()事件验证电子邮件id,我打算这样做:
$('#email').blur(function(){
//make ajax call , check if duplicate email exist and if duplicate is there do :
$('#email-error').html('duplicate email exisit');
});
然而,当我使用blur()时,如果我在输入框上单击其他位置(发生了模糊事件),这时候如果我切换到另一个选项卡,然后再次回到(浏览器的)选项卡,我的页面会定住——有人能给我一个解决方案吗?
Instead of blur use .change function.The change event is sent to an element when its value changes.Your blur event or focusout event will unnecessary fire ajax request everytime your textbox looses focus whether the data has changed or not.
$('#email').change(function(){
//make ajax call , check if duplicate email exist and if duplicate is there do :
$('#email-error').html('duplicate email exisit');
});
Instead of blur add like this
$('#email').focusout(function(){
$('#email-error').html('duplicate email exisit');
});