I am hoping to track the position of the mouse cursor, periodically every t mseconds.(我希望每隔t毫秒定期跟踪鼠标光标的位置。)
So essentially, when a page loads - this tracker should start and for (say) every 100 ms, I should get the new value of posX and posY and print it out in the form.(基本上,当一个页面加载时 - 这个跟踪器应该开始,并且(例如)每100毫秒,我应该获得posX和posY的新值并在表单中打印出来。)
I tried the following code - but the values do not get refreshed - only the initial values of posX and posY show up in the form boxes.(我尝试了以下代码 - 但值不会刷新 - 只有posX和posY的初始值显示在表单框中。) Any ideas on how I can get this up and running ?(关于如何启动和运行的任何想法?)
<html>
<head>
<title> Track Mouse </title>
<script type="text/javascript">
function mouse_position()
{
var e = window.event;
var posX = e.clientX;
var posY = e.clientY;
document.Form1.posx.value = posX;
document.Form1.posy.value = posY;
var t = setTimeout(mouse_position,100);
}
</script>
</head>
<body onload="mouse_position()">
<form name="Form1">
POSX: <input type="text" name="posx"><br>
POSY: <input type="text" name="posy"><br>
</form>
</body>
</html>
ask by Hari translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…