例如mousedown时把事件f1绑定到mouseup
并设置setCapture
这样mouseup时就触发f1
但设置了setCapture的话如果鼠标移动到文档外放开鼠标就触发不了mouseup事件
不过就能触发losecapture事件,所以就可以用losecapture代替mouseup
losecapture和mouseup的作用效果是一样的,这里是为了针对不同的情况

解决方案 »

  1.   

    好象看懂了,但不是很明白,我写的东西中没有效果噢(指教下该怎么写吧)
    按道理说鼠标离开浏览器应该清空onmousedown事件 ,但是没有效果噢
    <body> 
    <div  style=" width:200px; height:190px;  position:absolute;border:1px solid #666666"> 
    <div id="gg" style=" width:200px; height:40px; background:#FFFF99; "> </div> 
    <div style=" width:200px; height:150px;"> </div> 
    </div> 
    </body> 
    <script> 
    var gg = document.getElementById("gg") gg.onmouseover = function(){   document.onmousedown =function(e) 
          { 
            e = e||event 
           gg.setCapture() 
            var  tempx = e.clientX - gg.parentNode.offsetLeft 
            var  tempy = e.clientY - gg.parentNode.offsetTop 
            document.onmousemove = function(e) 
                { 
                      e = e||event 
                      gg.parentNode.style.left = (e.clientX-tempx)+"px" 
                      gg.parentNode.style.top = (e.clientY-tempy)+"px"             }  
     
      gg.onlosecapture =function(){
           gg.releaseCapture() 
                document.onmousemove = null; 
    document.onmousedown = null; 
      }


    </script> 
      

  2.   

    错了错了
    不好意思设置了setCapture的话如果切换到其他窗口(例如alt+tab切换)放开鼠标就触发不了mouseup事件 
    不过这时就能触发losecapture事件所以两个都需要的,针对不同的情况
    gg.onmouseup = gg.onlosecapture =function(){