慕盖茨9705228
2016-06-30 11:45
<html>
<head>
<title>事件流</title>
<meta charset="utf-8"></head>
<body>
<div id="box">
<a href="http://www.baidu.com" id="go" onclick="stopgoto()">go</a>
</div>
<script type="text/javascript">
function stopgoto(event){
alert("hello");
event.stopPropagation();
event.stopDefault();
}
</script>
</body>
</html>
你这个事件流,并没有定义a的父元素div的事件,没所谓的阻止不阻止,a的stopPropagation是阻止冒泡到div,不是阻止自身事件动作
<html> <head> <title>事件流</title> <meta charset="utf-8"> </head> <body> <div id="box" style="height: 100px;width: 50px;border-radius: 50px 50px;background-color: green;"> <a href="http://www.baidu.com" target="_blank" onclick="stopgoto(event)">go</a> </div> <script type="text/javascript"> window.onload = function() { var div = document.getElementById("box"); box.onclick = function() { alert("imooc"); } } function stopgoto(event) { alert("hello"); event.stopPropagation(); } </script> </body> </html>
DOM事件探秘
99544 学习 · 1197 问题
相似问题
回答 3
回答 6