日期:2014-05-16 浏览次数:20402 次
<div id="parent" style="width:300px;height:300px;background:red;padding:50px"><div id="children" style="width:200px;height:200px;background:white;"></div></div>
<script> var $ = function(id){ return document.getElementById(id); } $('parent').onclick=function(){ alert(1); }; $('children').onclick=function(e){ alert(2); //1.js 阻止事件冒泡到父元素 if (e.stopPropagation){ e.stopPropagation();} else {e.cancelBubble = true;} //2.如果是用jQuery Lib来绑定事件则 return false;即可 //return false; }; </script>