阻止事件冒泡

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<style>
.d1{
width: 500px;
height: 500px;
background: red;
}
.d2{
width: 300px;
height: 300px;
background: yellow;
}
.d3{
width: 100px;
height: 100px;
background: blue;
}
</style>
<body>
<div class="d1">
<div class="d2">
<div class="d3"></div>
</div>
</div>
<script src="js/jquery-1.12.4.js"></script>
<script>
$(".d1").click(function () {
console.log("d1");
})
$(".d2").click(function () {
console.log("d2");
})
$(".d3").click(function () {
console.log("d3");
return false; /*阻止事件冒泡*/
})
</script>
</body>
</html>
posted @ 2019-08-10 21:33  Hi前端  阅读(617)  评论(0编辑  收藏  举报