この記事では、JS Webページでオンラインでマウス座標値を取得する方法について説明します。参照のためにそれを共有してください。特定の実装方法は次のとおりです。
次のようにコードをコピーします:<html>
<head>
<Meta http-equiv = "content-type" content = "text /html; charset = gb2312" />
<title>マウス座標を表示</title>
</head>
<body onmousemove = "micro $ oftmousemove()">
<スクリプト言語= "javascript">
if(navigator.appname == 'netscape')
{
document.captureevents(event.mousemove);
document.onmousemove = netscapemousemove;
}
function netscapemousemove(e){
if(e.screenx!= document.test.x.value && e.screeny!= document.y.value);
{
document.test.x.value = e.screenx;
document.test.y.value = e.screeny;
}
}
関数micro $ oftmousemove(){
if(window.event.x!= document.test.x.value && window.event.y!= document.test.y.value);
{
document.test.x.value = window.event.x;
document.test.y.value = window.event.y;
}
}
</script>
<form name = "test">
x:<input type = "text" name = "x" size = "4">
y:<入力typue = "text" name = "y" size = "4">
</form>
</body>
</html>
この記事がみんなのJavaScriptプログラミングに役立つことを願っています。