简体   繁体   English

当点击部分弹出文档时,Onblur事件在IE中错误地触发

[英]Onblur event mistakenly fires in IE when parts of popup document are clicked

I have a bunch of small pop-up pages that are designed to self-close when they lose focus - ie 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. 不幸的是,在IE8中,当用户开始在弹出页面内填写输入表单时,也会出现模糊。 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: 这是我在几个弹出窗口中使用的模糊代码(在.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();  
}

Instead of using blur() you can use jQuery's focusin() and focusout() handlers. 您可以使用jQuery的focusin()focusout()处理程序,而不是使用blur()

The focusin event is sent to an element when it, or any element inside of it, gains focus. focusin或其中的任何元素获得焦点时, focusin事件将被发送到元素。

The focusout event is sent to an element when it, or any element inside of it, loses focus. focusout事件或其中的任何元素失去焦点时,焦点focusout事件将被发送到元素。

These are distinct from blur() in that it supports detecting the loss of focus from parent elements (in other words, it supports event bubbling). 这些与blur()的区别在于它支持从父元素检测焦点丢失(换句话说,它支持事件冒泡)。

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

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