javascript 捕获与泡沫(事件)

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 捕获与泡沫(事件)相关的知识,希望对你有一定的参考价值。

# Explanation

Events can be activated at two occasions: At the beginning ("capture"), and at the end ("bubble").
Events are executed in the order of how they're defined. Say, you define 4 event listeners.

## The alert boxes will pop up in this order

- 2 (defined first, using capture=true)
- 4 (defined second using capture=true)
- 1 (first defined event with capture=false)
- 3 (second defined event with capture=false)
window.addEventListener("click", function(){alert(1)}, false);
window.addEventListener("click", function(){alert(2)}, true);
window.addEventListener("click", function(){alert(3)}, false);
window.addEventListener("click", function(){alert(4)}, true);

// Order of execution

// 2
// 3
// 1
// 3

以上是关于javascript 捕获与泡沫(事件)的主要内容,如果未能解决你的问题,请参考以下文章

JavaScript事件捕获冒泡与捕获

理解:javascript事件捕获 与 事件冒泡

JavaScript事件冒泡与捕获

JavaScript---事件冒泡事件捕获

你根本不懂Javascript: HTML事件捕获与冒泡

JavaScript事件冒泡和事件捕获