e.stopPropagation()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<style>
.father{
width: 200px;
height: 200px;
background-color: #e64942;
align-content: center;
border: 1px solid;
/*margin: 100px auto;*/
}
.son{
width: 150px;
height: 150px;
background-color: pink;
/*margin: 175px auto;*/
}
</style>
</head>
<body>
<div class="father">
<div class="son">son</div>
</div>
<script>
//冒泡阶段
var son=document.querySelector('.son');
son.addEventListener('click',fn,false);
function fn(e) {
alert('son');
e.stopPropagation();//阻止冒泡 propagation:传播
e.cancelBubble=true; //阻止冒泡 早版本支持stopPropagation
}
var father=document.querySelector('.father');
father.addEventListener('click',function () {
alert('father');
},false);
document.addEventListener('click',function () {
alert('document');
})
</script>
</body>
</html>