运行 ❯
获取您的
自己的
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <style> div { width: 200px; height: 100px; border: 1px solid black; } </style> <body> <h1>HTML DOM Events</h1> <h2>The onmousemove Event</h2> <p>Assign an "onmousemove" event to a div element.</p> <div onmousemove="myFunction(event)"></div> <p>Mouse over the rectangle above, and get the coordinates of your mouse pointer.</p> <p id="demo"></p> <script> function myFunction(e) { let x = e.clientX; let y = e.clientY; let coor = "Coordinates: (" + x + "," + y + ")"; document.getElementById("demo").innerHTML = coor; } </script> </body> </html>