jQuery事件冒泡
事件的冒泡(Bubble)
指的是事件的向上传导,当后代元素的事件被触发时,其祖先元素的相同时间也会被触发
并不是点击了三个重叠的位置导致了三个弹窗,而是事件的冒泡,导致了点3会出现1,2
点击3会出现事件冒泡,事件冒泡会冒到父亲身上,如果父亲身上也有点击事件,就会运行父亲绑定的事件
js的冒泡是事件冒泡
比如e的事件冒泡
因为q有click事件才会接受到div的冒泡
并不是将事件赋值在一个父级身上
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script src="../jquery-3.5.1.min.js"></script>
</head>
<style>
.q{
position:absolute;
width: 400px;
height: 400px;
background-color: aqua;
}
.w{
position:absolute;
left: 400px;
width: 300px;
height: 300px;
background-color: red;
}
.e{
position:absolute;
left: 300px;
width: 200px;
height: 200px;
background-color: green;
}
</style>
<body>
<div class="q">
<div class="w">
<div class="e">
</div>
</div>
</div>
<script>
$('.q').click(function(){
alert(1);
})
$('.w').click(function(){
alert(2);
})
$('.e').click(function(){
alert(3);
})
</script>
</body>
</html>