运行 ❯
获取您
自己
的网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 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>Use the addEventListener() method to attach a "mousemove" event to a div element.</p> <div id="myDIV"></div> <p>Mouse over the rectangle above, and get the coordinates of your mouse pointer.</p> <p id="demo"></p> <script> document.getElementById("myDIV").addEventListener("mousemove", function(event) { myFunction(event); }); function myFunction(e) { let x = e.clientX; let y = e.clientY; let coor = "Coordinates: (" + x + "," + y + ")"; document.getElementById("demo").innerHTML = coor; } </script> </body> </html>