运行 ❯
获取您
自身
网站
×
更改方向
保存代码
更改主题,深色/浅色
前往 Spaces
<!DOCTYPE html> <html> <body> <h1>Mouse Events</h1> <h2>The offsetX Property</h2> <p>The offsetX property returns the x-coordinate the mouse cursor, relative to the target element.</p> <p>In this example, the red DIV is the target element.</p> <p>Click inside the red DIV element:</p> <div onclick="myFunction(event)" style="border:2px solid red;height:100px"></div> <p id="demo"></p> <script> function myFunction(event) { let x = event.offsetX; document.getElementById("demo").innerHTML = "The x-coordinate is: " + x; } </script> </body> </html>