为什么在使用事件冒泡时没有调用无效事件的事件监听器? [英] Why is the event listener for the invalid event not being called when using event bubbling?

查看:112
本文介绍了为什么在使用事件冒泡时没有调用无效事件的事件监听器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试向文档的无效事件添加事件监听器时,当我使用这样的默认事件冒泡时,它不会被调用。

When I try add an event listener to the invalid event of the document it is not called when I use the default event bubbling like this.

document.addEventListener("invalid", function (e) {
    console.log(e.target);
}, false);

当我将最后一个参数设置为 true 事件监听器像预期一样被调用。感谢什么是事件冒泡和捕获?我想我明白了它们之间的区别事件捕获和冒泡,但我不明白这是如何适用于我的情况。为什么它在这里有所作为?

When I set the last parameter to true the event listener is called like expected. Thanks to What is event bubbling and capturing? I think I understand the difference between event capturing and bubbling, but I don't understand how this applies to my case. Why is it making a difference here?

推荐答案

根据 MDN参考,通常是准确的,在这种情况下似乎与现实相符,无效活动不冒泡。它们仅在输入和表单上触发。

According to the MDN reference, which is usually accurate and which appears to match reality in this case, invalid events do not bubble. They fire only on the input and the form.

这篇关于为什么在使用事件冒泡时没有调用无效事件的事件监听器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆