DOM事件流
dom事件流分为三个阶段- 捕获阶段
- 当前目标阶段
- 冒泡阶段
例子
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title></title>
<style>
.father{
width:300px;
height:300px;
border:1px solid red;
}
.son{
width:200px;
height:200px;
border:1px solid blue;
}
</style>
</head>
<body>
<div class="father">
<div class="son"></div>
</div>
<script>
var father=document.querySelector('.father');
var son=document.querySelector('.son');
father.addEventListener('click',function(){
alert('father');
},true)
son.addEventListener('click',function(){
alert('son');
},false)
</script>
</body>
</html>
结果:儿子在冒泡阶段,父亲在捕获阶段,所以点击儿子,先执行父亲函数,然后执行儿子函数