我有以下内容:
<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 之后停在最后一个坐标?< / p>
使用firefox 3.6.3
提前致谢:)
答案 0 :(得分: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>