2010-06-02 94 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>