取消冒泡不需要做兼容的吧
用cancelBubble 标准浏览器好像也可以取消冒泡呀? 那个stopPropagation好像不用用了吧
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
div{padding:30px 50px;}
#div1{background:red;}
#div2{background:green;}
#div3{background:blue;}
</style>
<script>
window.onload=function ()
{
var oDiv1=document.getElementById('div1');
var oDiv2=document.getElementById('div2');
var oDiv3=document.getElementById('div3');
oDiv1.onclick=function ()
{
alert(this.id);
}
oDiv2.onclick=function (ev)
{
var ev=ev||event;
ev.cancelBubble=true;
//ev.stopPropagation();
alert(this.id);
}
}
</script>
</head>
<body>
<div id="div1">
<div id="div2">
<div id="div3"></div>
</div>
</div>
</body>
</html>