2
社区成员
发帖
与我相关
我的任务
分享
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
.father {
width: 500px;
height: 500px;
background-color: pink;
}
.son {
width: 300px;
height: 300px;
background-color: purple;
}
</style>
<body>
<div class="father">
<div class="son"></div>
</div>
<script>
let f = document.querySelector('.father');
let s = document.querySelector('.son');
f.addEventListener('mouseenter', function () {
alert('我是爸爸')
})
s.addEventListener('mouseenter', function () {
alert('我是儿子')
})
document.addEventListener('mouseenter', function () {
alert('我是yeye')
})
</script>
</body>
</html>
在这种情况下,为什么事件冒泡先执行的是,document——father——son;侦听事件,第三个参数默认为false,开启的是冒泡阶段;不应该事件执行流程为,son——father——document嘛