javascript - 为什么 event.bubbles 对于 "focusin"和 "focusout"是假的?

标签 javascript jquery focusin

几分钟前,我回答了这个问题:
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);
});​

focusinfocusout 给我 e.bubbles == false

这是 jQuery 的错误还是我错过了这里显而易见的地方?

最佳答案

听起来像是 jQuery 中的错误。 您是否在 native 支持 focusinfocusout 的浏览器上测试过这个? (例如,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/

相关文章:

javascript - Flask,Ajax,在 url 中获取 ajax url 的值

javascript - 仅滑动移动菜单

javascript - 如何从 focusout 中排除 Id

jquery - <legend> 不会收到 :focus event?

javascript - Javascript 代码混淆中的原型(prototype)

javascript - 如何向特定 channel 发送消息

javascript - 将 contenteditable 文本的 innerHTML 转换为普通字符串

javascript - 查看文件夹并使用通配符的函数

javascript - jquery:当我点击一个div时,将焦点放在一个文本框上

javascript - 多选列表框不工作