实例-冒泡与捕获的不同。
div1
点击 p1-冒泡。
div2
点击 p2-捕获。
// 2.捕获。
document.getElementById(“p2”).addEventListener(“click”, function () {
e.stopPropagation(); // 阻止事假默认行为
alert(“p2”);
}, true);
document.getElementById(“capture”).addEventListener(“click”, function () {
alert(“div2”);
}, true);
e.stopPropagation(); // 阻止事件默认行为