前端事件传播,“在目标对象本身上注册的捕获处理程序不会被调用”!????

前端事件传播,“在目标对象本身上注册的捕获处理程序不会被调用”,js权威指南上是这么写的,但用addeventlisten添加父子元素的click事件,第三个捕获参数都设置为true,为什么父子元素的click事件都会被调用?_VI2GT8~I251E~QN5%]_}6S.png源代码02H]ES}30DQBF4SV]8$O8ST.png为什么click son!也会输出?不是在目标对象本身上注册的捕获处理程序不会被调用吗?

阅读 2.7k
4 个回答

文档

For event listeners attached to the event target, the event is in the target phase, rather than the capturing and bubbling phases. Events in the target phase will trigger all listeners on an element in the order they were registered, regardless of the useCapture parameter.

addeventlistener第三个参数只是决定事件在捕获时触发还是在冒泡时触发,和是否触发无关吧?

新手上路,请多包涵

这是事件冒泡,禁止一下就行,写这东西干嘛用的?

推荐问题