我在尝试记录点击的确切坐标时遇到问题。第一个readMouseMove函数正是如何工作的。滚动时显示鼠标坐标。第二个mouseClick函数应该仅在单击时记录坐标。目前它与上面的函数相同,但似乎我只能使用clientx / y事件一次。是否有办法记录鼠标点击而不是相对于某个对象?
<script type='text/javascript'>
function readMouseMove(e) {
var xandy = 'x=' + e.clientX + " " +'y=' + e.clientY;
document.getElementById('divOne').innerHTML = xandy;
};
function mouseClick(e) {
var clickers = 'x=' + e.clientX + " " +'y=' + e.clientY;
document.getElementById('divTwo').innerHTML = clickers;
};
function clearAll() {
document.getElementById('divTwo').innerHTML = " "
};
document.onmousemove = readMouseMove;
document = mouseClick;
</script>
答案 0 :(得分:1)
您要在此处mouseClick
分配document object
:
document = mouseClick;
应该是:
document.onclick = mouseClick;