Javascript 在mousedown上创建鼠标捕获功能?

Javascript 在mousedown上创建鼠标捕获功能?,javascript,firefox,Javascript,Firefox,我有以下资料: <html> <script type="text/javascript"> document.onmousemove = getCursorXY; function getCursorXY(e) { document.getElementById('cursorX').value = (window.Event) ? e.pageX : event.clientX + (document.

我有以下资料:

<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>

document.onmousemove=getCursorXY;
函数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);
}
这样,在加载页面和移动鼠标时,我的鼠标坐标将显示在输入字段中。当我按下按钮时,我如何使其仅工作,然后当我按下按钮时,在最后一个坐标处停止

使用firefox 3.6.3


提前感谢:)

试试这样的东西

<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> 

函数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=函数(){
document.getElementById(“按钮”).onmousedown=getCursorXY;
}

试试这样的方法

<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> 

函数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=函数(){
document.getElementById(“按钮”).onmousedown=getCursorXY;
}