几分钟前,我回答了这个问题:
What is the difference between focusin/focusout vs focus/blur in jQuery?
答案是:
简答:focusin
气泡,focus
没有。
focusout
气泡,blur
没有。
我测试过,确实如此,但是我在尝试设置 DEMO 时遇到了一个奇怪的事情:
$('#test').on('focusin focusout focus blur change', function(e) {
console.log(e.type + 'event bubles? : ' + e.bubbles);
});
focusin
和 focusout
给我 e.bubbles == false
这是 jQuery 的错误还是我错过了这里显而易见的地方?
最佳答案
听起来像是 jQuery 中的错误。 您是否在 native 支持 focusin
和 focusout
的浏览器上测试过这个? (例如,IE?)因为如果没有,您正在测试 jQuery 的模拟支持的标志。
我已经划掉了上面的“听起来像个错误”部分,因为 jQuery 没有声称要规范化文档中的 bubbles
属性。因此,由于它不能保证,因此不必在模拟事件中支持它。 (请注意,如果我在 IE7 上运行您的演示,我会得到 undefined
,因为 IE7 不支持 DOM3 事件 bubbles
属性。)仍然是一个问题,但也许不是 错误。 :-)
更新:
对 the jQuery ticket 的回应:
The documentation doesn't claim to normalize the event.bubbles property. You can look for it in event.originalEvent but that will be whatever the platform provided, unnormalized.
所以我上面的猜测是正确的。这不是一个错误,因为他们没有声称要对其进行规范化。 :-)
关于javascript - 为什么 event.bubbles 对于 "focusin"和 "focusout"是假的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10584488/