取消捕获事件
<html lang="en">
<head>
<meta charset="utf-8">
<title>取消捕获事件</title>
<style type="text/css">
#b{flat:left;width:200px;height:200px;background:yellow;margin:20px;}
#b1 {float:left;margin:20px;width:100px; height:100px;background:red;}
</style>
</head>
<body>
<div id="b">
<div id="b1">
</div>
</div>
<script type="text/javascript">
var bs1=document.getElementById('b1');
function buhuo(id) {
var b=document.getElementById(id);
var st="你好,我是bs";
sa=st.substr(0,st.length-1);
b.addEventListener('click',function(e) {
var e=e||event;
e.stopPropagation(); //stopPropagation()取消事件传播,事件传播包括事件冒泡和捕获事件
alert(sa);
//e.stoplmmediatePropagation(); //stoplmmediatePropagation()不仅阻止冒泡事件和捕获事件,还阻止元素其他事件,建议用stopPropagation()
},true);
}
new buhuo('b');
bs1.οnclick=function() {
alert("你好,我是b1");
};
</script>
</body>
</html>