jQuery blur() on Chrome not working

岁酱吖の 提交于 2019-12-11 01:45:18

问题


I'm on MacOSX running this http://jsfiddle.net/q84wv/ on Chrome latest version.

It won't work, while running that on Firefox it works perfectly, any clue?


回答1:


Assuming that you want the alert() to be triggered either when the user tabs out from the anchor, or completes a click event, this should work:

$('.menu a').on('blur mouseup',function(){
    alert('oh');
});

Check this jsFiddle.

It really depends what you're classing as blur here. If you're wanting it to trigger whenever the user's mouse leaves the element, you can use mouseleave instead:

$('.menu a').on('blur mouseleave',function(){
    alert('oh');
});



回答2:


you must first focus then blur

$('.menu a').click(function() {
  $(this).focus();
});

$('.menu a').on('blur',function(){
    alert('oh');
});

jsFiddle




回答3:


Well for that first you have to apply blur and blur the menu out.

$('.menu a').click(function() {
  $('.menu a').blur();
});

$('.menu a').on('blur',function(){
    alert('oh');

  });

You were trying to alert if that menu has been blurred. But you were not blurring it. That's why it was not working.

FIddle : http://jsfiddle.net/q84wv/4/

Now click on the menu item(s) and you will find the alert coming up .



来源:https://stackoverflow.com/questions/18250120/jquery-blur-on-chrome-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!