onblur事件不适用于谷歌浏览器 [英] onblur event not working with google chrome

查看:748
本文介绍了onblur事件不适用于谷歌浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正尝试使用onblur事件来关闭一个窗口。它在IE,Firefox和Safari浏览器中工作正常,但事件不会在Chrome中触发。是一个在Chrome中的错误或者是一个错误我知道这是一年前的事,但它显示出来了我试图解决同样的问题。



似乎Chrome并没有考虑到一些元素,比如body和anchor,都是可以聚焦的。根据以下页面,您可以通过设置 tabindex 属性使任何元素可以聚焦(从而激活模糊事件):http://www.quirksmode.org/dom/events/blurfocus.html



像这样:

 < a href =#tabindex =0onblur =alert('blur')>模糊我< / a> 


I am trying to use onblur event to close a window. Its working fine in IE, Firefox and safari, but the event does not trigger in chrome. is that a bug in chrome or a mistake from me

解决方案

I realize this was over a year ago, but it showed up for me in Google while trying to solve this same issue.

It seems Chrome does not consider some elements, like body and anchors, to be "focusable". According to the following page, you can make any element focusable (thereby activating the blur event) by setting the tabindex attribute: http://www.quirksmode.org/dom/events/blurfocus.html

Like so:

<a href="#" tabindex="0" onblur="alert('blur')"> blur me </a>

这篇关于onblur事件不适用于谷歌浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆