บทความนี้อธิบายวิธีการรับค่าพิกัดของเมาส์ออนไลน์โดย JS หน้าเว็บ แบ่งปันสำหรับการอ้างอิงของคุณ วิธีการใช้งานเฉพาะมีดังนี้:
คัดลอกรหัสดังนี้: <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;
-
ฟังก์ชั่น 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;
-
-
ฟังก์ชั่น 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: <อินพุต type = "text" name = "x" size = "4">
y: <อินพุต typue = "text" name = "y" size = "4">
</form>
</body>
</html>
ฉันหวังว่าบทความนี้จะเป็นประโยชน์กับการเขียนโปรแกรม JavaScript ของทุกคน