<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<script type="text/javascript" src="jquery-3.2.0.js"> </script>
</head>
<body>
<div>Div element</div>
<p>
Paragraph Element
<span>span element</span>
</p>
<script type="text/javascript">
$(function(){
$("div").click(function(){
alert("You have clicked Div element");
});
$("span").click(function(){
alert("You have clicked span element");
});
$("p").click(function(){
alert("You have clicked Paragraph element");
});
});
</script>
</body>
</html>
点击span元素时首先触发span的单击事件,然后p元素的单击事件也被触发了(p是span的父元素),这就是js中的事件冒泡
那么怎么防止事件冒泡呢???????