时间:2021-07-01 10:21:17 帮助过:3人阅读
本文实例讲述了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程序设计有所帮助。