screenX 事件属性

定义和用法

screenX 事件属性可返回事件发生时鼠标指针相对于屏幕的水平坐标。

语法

  1. event.screenX

实例

下面的例子可显示出事件发生时鼠标指针的坐标:

  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4. function show_coords(event)
  5. {
  6. x=event.screenX
  7. y=event.screenY
  8. alert("X coords: " + x + ", Y coords: " + y)
  9. }
  10. </script>
  11. </head>
  12. <body onmousedown="show_coords(event)">
  13.  
  14. <p>Click in the document. An alert box will alert
  15. the x and y coordinates of the cursor.</p>
  16.  
  17. </body>
  18. </html>