代码:
<div style="background:#CFF; width:300px; height:200px;" id="one" onmousedown="dosomething(this)">
    <div style="background:#FFC; width:200px; height:100px;" id="two" onmousedown="dosomething(this)">
        <div style="background:#666; width:100px; height:50px;" id="three" onmousedown="dosomething(this)"></div>
    </div>
</div>
过程:点击id为three的div,另两个div都会执行onmousedown事件,现在只需要id为three的执行onmousedown事件,其他两个div不执行

解决方案 »

  1.   

    冒泡
    function isMouseLeaveOrEnter(e, handler) { 
    if (e.type != 'mouseout' && e.type != 'mouseover') return false; 
    var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement; 
    while (reltg && reltg != handler) 
    reltg = reltg.parentNode; 
    return (reltg != handler); 
    }
    http://topic.csdn.net/u/20081223/08/bb0bbf90-67b2-47a7-9b9a-1d3e2a5e516c.html
      

  2.   

    在dosomething里面阻止冒泡。。
      

  3.   

    <div style="background:#666; width:100px; height:50px;" id="three" onmousedown="dosomething(this,event)"></div>
    function dosomething(obj,e){
    alert(obj.innerHTML);
    if(e && e.stopPropagation){
      //W3C取消冒泡事件
      e.stopPropagation();
      }else{
      //IE取消冒泡事件
      window.event.cancelBubble = true;
      }
    };