2010-06-02 111 views
1

我有以下幾點:Envoking鼠標捕捉功能onmousedown?

<html> 
    <script type="text/javascript"> 
     document.onmousemove = getCursorXY; 

     function getCursorXY(e) { 
      document.getElementById('cursorX').value = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft); 
      document.getElementById('cursorY').value = (window.Event) ? e.pageY : event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); 
     } 
    </script> 

    <body> 
     <input id="cursorX" size="3"> 
     <input id="cursorY" size="3"> 
     <input type="button" id="button"> 
    </body> 
</html> 

有了這個每當我把鼠標移動我的鼠標座標顯示在輸入字段在頁面加載時和。我怎樣才能使這項工作只有當我mousedown結束#button然後停在最後的座標當我mouseup只有#button

用firefox 3.6.3

感謝提前:)

回答

1

嘗試這樣的事情。

<html> 
    <script type="text/javascript"> 
     function getCursorXY(e) { 
      document.getElementById('cursorX').value = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft); 
      document.getElementById('cursorY').value = (window.Event) ? e.pageY : event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop); 
     } 

     window.onload = function() { 
      document.getElementById("button").onmousedown = getCursorXY; 
     } 
    </script> 

    <body> 
     <input id="cursorX" size="3"> 
     <input id="cursorY" size="3"> 
     <input type="button" id="button"> 
    </body> 
</html>