JavaScript中事件捕获(Event capturing)-------------->由外向内,事件冒泡(Event bubblin)---------->由内向外

时间:2021-08-01 01:53:28
 addEventListener("click", function() {}, useCapture:false);
<!DOCTYPE html>
<html lang="en">
<head> </head>
<body>
<div id="content" class="c1">
<a id="b">hhaha</a>
<a href="#!/fdaf">fda</a>
<a href="#!/fdaaa">fdf</a>
</div>
<script>
document.getElementById("b").addEventListener("click", function() {
//this.href = this.href.replace("?", "#");
console.log("inner");
},true); window.addEventListener("hashchange", function() {
console.log(location.hash);
}, false); document.getElementById("content").addEventListener("click", function() {
console.log("outer");
},true);
</script>
</body>
</html>

-------------->outer

-------------->inner

默认是不用捕获的。---------->由内向外

------------->inner

------------->outer

区别于xmlhttp.send("GET", url, async:true);--------->表示是否异步async