简体   繁体   English

Chrome上的jQuery blur()无效

[英]jQuery blur() on Chrome not working

I'm on MacOSX running this http://jsfiddle.net/q84wv/ on Chrome latest version. 我在MacOSX上运行这个http://jsfiddle.net/q84wv/Chrome最新版本上。

It won't work, while running that on Firefox it works perfectly, any clue? 它不会工作,而在Firefox上运行它是完美的,任何线索?

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: 假设您希望在用户从锚点中标记出来时触发alert() ,或者完成click事件,这应该可以:

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

Check this jsFiddle . 检查这个jsFiddle

It really depends what you're classing as blur here. 这真的取决于你在这里分类的blur If you're wanting it to trigger whenever the user's mouse leaves the element, you can use mouseleave instead: 如果您希望每当用户的鼠标离开元素时触发它,您可以使用mouseleave代替:

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

you must first focus then blur 你必须首先关注然后模糊

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

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

jsFiddle 的jsfiddle

Well for that first you have to apply blur and blur the menu out. 那么首先你必须应用blur并模糊菜单。

$('.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/ 飞行: http//jsfiddle.net/q84wv/4/

Now click on the menu item(s) and you will find the alert coming up . 现在点击菜单项,你会发现即将发出警报。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM