gpt4 book ai didi

javascript - onmousedown 调用鼠标捕获函数?

转载 作者:行者123 更新时间:2023-11-28 02:54:47 28 4
gpt4 key购买 nike

我有以下内容:

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

这样,当页面加载时以及每当我移动鼠标时,我的鼠标坐标就会显示在输入字段中。我怎样才能当我在#button上鼠标按下时工作,然后当我仅在#button上按下鼠标时停止在最后一个坐标?

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

关于javascript - onmousedown 调用鼠标捕获函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2954704/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com