单击弹出文档的部分内容时,在 IE 中错误地触发 Onblur 事件

发布于 2024-09-16 04:09:25 字数 516 浏览 9 评论 0原文

我有一堆小弹出页面,它们被设计为在失去焦点时自动关闭 - 即用户单击父文档。

不幸的是,在 IE8 中,当用户开始在弹出页面内填写输入表单时,也会发生模糊。 事实上,单击表单内的任何地方都会导致这种情况,甚至当用户意外单击某些文本时也是如此。这些项目似乎不是弹出文档的一部分。

我怎样才能让他们这样呢?

这是我在几个弹出窗口上使用的模糊代码(在 .js 脚本内):

var fClose=0 

onload=function() {   
 fClose=0  
 setTimeout("doClose()",111);  
 document.onblur=Blur_Me;  
 document.onfocusout = Blur_Me;  
}  

function Blur_Me(){  
 fClose=1;  
 setTimeout("doClose()",111);  
}    
function doClose(){  
 if(fClose)close();  
}

I have a bunch of small pop-up pages that are designed to self-close when they lose focus - i.e. the user clicks on the parent document.

Unfortunately in IE8, the blur also occurs when the user starts to fill out an input form inside the pop-up page.
Indeed clicking anywhere inside the form causes this, or even when the user accidentally clicks on some text. It seems these items are not part of the pop-up document.

How can I make them so?

Here's my blur code (inside a .js script) that I use on the several pop-ups:

var fClose=0 

onload=function() {   
 fClose=0  
 setTimeout("doClose()",111);  
 document.onblur=Blur_Me;  
 document.onfocusout = Blur_Me;  
}  

function Blur_Me(){  
 fClose=1;  
 setTimeout("doClose()",111);  
}    
function doClose(){  
 if(fClose)close();  
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

万水千山粽是情ミ 2024-09-23 04:09:25

您可以使用 jQuery 的 focusin()focusout() 处理程序来代替使用 blur()

当元素或其内部的任何元素获得焦点时,focusin 事件将发送到该元素。

当元素或其内部的任何元素失去焦点时,focusout 事件将发送到元素。

它们与blur() 不同,因为它支持检测父元素失去焦点(换句话说,它支持事件冒泡)。

Instead of using blur() you can use jQuery's focusin() and focusout() handlers.

The focusin event is sent to an element when it, or any element inside of it, gains focus.

The focusout event is sent to an element when it, or any element inside of it, loses focus.

These are distinct from blur() in that it supports detecting the loss of focus from parent elements (in other words, it supports event bubbling).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文