我在一个 div 中有两个输入框,我想将该 div 隐藏在输入的 focusOut 上,但前提是它们都没有焦点。
这是一个常见的 Firefox 问题(有人称其为遵守标准),但文档正文窃取了两者之间的焦点。
HTML
<div id="baz">
<input type="text" id="foo" name="foo" />
<input type="text" id="bar" name="bar" />
</div>
jQuery
// jQuery Example
jQuery(":input").focusout(function(){
// Don't do anything if one of the input boxes has focus
if( jQuery(":input").is( jQuery(document.activeElement) ){ return; }
// Hide the container if one of the inputs loose focus
jQuery(this).parents("div").css("display","none");
}
虽然这是一个常见的错误,但我忘记了我过去是如何解决的。我认为这与在检查activeElement
.