javascript Chrome 上的 jQuery blur() 不起作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18250120/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery blur() on Chrome not working
提问by itsme
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 上运行它时它可以完美运行,有什么线索吗?
回答by BenM
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()
用户从锚点退出或完成点击事件时触发 ,这应该有效:
$('.menu a').on('blur mouseup',function(){
alert('oh');
});
Check this jsFiddle.
检查这个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:
这真的取决于你在blur
这里分类什么。如果您希望它在用户鼠标离开元素时触发,则可以mouseleave
改用:
$('.menu a').on('blur mouseleave',function(){
alert('oh');
});
回答by Mohammad Masoudian
回答by The Dark Knight
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 .
现在单击菜单项,您会发现即将出现警报。