本文實例講述了JS網頁在線獲取鼠標坐標值的方法。分享給大家供大家參考。具體實現方法如下:
代碼如下:<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>顯示鼠標坐標</title>
</head>
<body onMousemove="micro$oftMouseMove()">
<SCRIPT LANGUAGE="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.test.y.value);
{
document.test.x.value = e.screenX;
document.test.y.value = e.screenY;
}
}
function 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: <INPUT TYPUE="TEXT" NAME="y" SIZE="4">
</FORM>
</body>
</html>
希望本文所述對大家的javascript程序設計有所幫助。