addEventListener and JavaScript event mechanism

JavaScript event handler is divided into two stages:

  • Capture Phase: transfer layer from the root node to event.target
  • Bubbling phase: event.target to the root node from the transfer layers

addEventListener (eventName, eventHandler, useCapture) the third parameter indicating whether to use a function of the capture phase, default is false.
useCapture default value is false to give priority to the right to deal with the event to sub-elements to deal with. If the ancestor node in the capture phase to put the event disposed of, children and grandchildren nodes may feel forced to look ignorant.
useCapture = false, meaning of the expression is: if one thing children can handle, then let the kids go deal with it.

Reference material

https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener

Guess you like

Origin www.cnblogs.com/weiyinfu/p/11967717.html