<div id="father" onmousedown="fun1(a,b,c)">
   <div id="son" onmousedown="fun2(c,d,e)">
     xxxxx
   </div>
</div>
有什么办法在son里面点击鼠标时,不相应father的鼠标点击事件?

解决方案 »

  1.   


    位置不固定。两个onmousedown都是拖拽功能。在考虑这是不是可以用停止冒泡来解决,但是不知道怎么弄。
      

  2.   

    取消事件冒泡...
    <html>
    <body>
    <script type="text/javascript">
    function fun1(){
    alert("fun1");
    }
    function fun2(oEvent, c, d, e){
    oEvent = oEvent || window.event;
    alert("fun2");
    if(document.all){
    oEvent.cancelBubble = true;
    }else{
    oEvent.stopPropagation();
    }
    }
    </script>
    <div id="father" onmousedown="fun1(event, 'a','b','c')">
       <div id="son" onmousedown="fun2(event, 'c','d','e')">
         xxxxx
       </div>
    </div>
    </body>
    </html>
      

  3.   

     <div id="father" onmousedown="fun1()">
       fun1;
       <div id="son" onmousedown="fun2();return false;">
         xxxxx fun2
       </div>
       fun1;
    </div>
    <script>
    var fun2run = false;
    function fun1(){
      if (fun2run){fun2run=false;return}
      alert(1)
    }
    function fun2(){
      fun2run=true;
      alert(2)
    }
    </script>
      

  4.   

    只用onmousedown="event.cancelBubble=true"就行了