阻止冒泡只对DOM2级事件处理程序有用,那html事件处理程序和DOM0级事件处理程序的冒泡影响呢?
都会阻止
这是我的代码,放在编辑器跑一下程序.
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<div id="box">
<input type="button" value="按钮" id="btn" onclick="show()">
<input type="button" value="按钮2" id="btn2">
<input type="button" value="按钮3" id="btn3">
<a href="event.html" id="go">跳转</a>
</div>
</body>
<script type="text/javascript">
// html
function show(){
alert('hello');
// event.stopPropagation();
}
// DOM0级
var btn2 = document.getElementById("btn2");
btn2.onclick = function(){
alert('nihao');
}
// DOM2级
var btn3 = document.getElementById("btn3");
btn3.addEventListener('click',showbtn3,false);
function showbtn3(event){
alert('btn3');
event.stopPropagation();
}
var box = document.getElementById("box");
box.addEventListener('click',showbox,false);
function showbox(){
alert('这是最外层的容器');
}
</script>
</html>
那两个不冒泡吧