gpt4 book ai didi

javascript - stopPropagation 作用在哪个阶段?

转载 作者:行者123 更新时间:2023-11-29 09:53:00 25 4
gpt4 key购买 nike

根据 quirksmode,现代浏览器有捕获阶段和冒泡阶段。参见 here.

如果我使用 stopPropagation在我的事件处理程序中(通过 bool 参数设置为任一阶段)它将如何运行?

它会双向工作吗?那就是如果我将它设置为捕获模式,它是否也会阻止冒泡阶段。反之亦然。

这是 W3 引用 ( stopPropagation )。

我正在对事件处理程序进行故障排除,需要准确了解 stopPropagation() 的功能。

最佳答案

在捕获阶段停止传播将阻止进一步的处理程序运行,包括在冒泡阶段注册的处理程序。

W3C documentation on event flow说(强调我的):

This specification defines three event phases: capture phase; target phase; and bubble phase. Event objects complete these phases in the specified order using the partial propagation paths as defined below. A phase must be skipped if it is not supported, or if the event object's propagation has been stopped. For example, if the Event.bubbles attribute is set to false, the bubble phase will be skipped, and if Event.stopPropagation() has been called prior to the dispatch, all phases must be skipped.

关于javascript - stopPropagation 作用在哪个阶段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18444225/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com