js事件冒泡、阻止事件冒泡

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title></title>
    <script type="text/javascript">
        function fun1 () {
            alert("parent(父)");
        }
		function fun2(){
            alert("child(子)");
		}
	 function fun3(){
            alert(button(按钮)");
		}
        function stopEvt(e) {
            e.stopPropagation();//阻止点击事件向上冒泡
        }
 
    </script>
</head>
<body>
    <div onclick="fun1()"><div onclick="fun2()"><button onclick="fun3();stopEvt(event)">按钮</button>
        </div>
    </div>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/Smile__1/article/details/85048625