Does stopPropgation stop the event from propagating in the capture phase?

前端 未结 3 1966
闹比i
闹比i 2021-02-07 06:38

I was looking at http://www.quirksmode.org/js/events_order.html and it is ambiguous in this part:

In the Microsoft model you must set the event’s ca

3条回答
  •  忘掉有多难
    2021-02-07 06:54

    Short answer: The order is:

    1. Capture (down)
    2. Target
    3. Bubble (up).

    If you call e.stopPropagation() in the capture phase (by setting the addEventListener()'s 3rd argument to true), it stops at 1, so 2 & 3 cannot receive it.

    If you call e.stopPropagation() in the bubble phase (by setting the addEventListener()'s 3rd argument to false or just not assign it), the 1 & 2 already complete, so it just prevents the event from bubbling up from the level where you call stopPropagation().

提交回复
热议问题