<div id="divId1" style="width:500px;height:500px;background-color:#3ac;text-align:center;" align="center"> <div id="divId2" style="width:400px;height:400px;background-color:#f1f; margin:0 auto;">开始啦</div> </div> document.getElementById(‘divId1‘).onclick = function(){ alert(‘divId1‘); } var eleDiv2 = document.getElementById(‘divId2‘); if(eleDiv2.addEventListener){ eleDiv2.addEventListener(‘click‘,function(evt){ alert(‘divId2‘); evt.stopPropagation(); },false); }else{ eleDiv2.attachEvent(‘onclick‘,function(evt){ alert(‘divId2‘); evt.cancelBubble = true; }); }
阻止事件冒泡(stopPropagation和cancelBubble)
原文:http://www.cnblogs.com/xiaoxian1369/p/4088448.html