pageX Mouse Event在JavaScript中的作用是什么?

原创
ithorizon 5个月前 (10-19) 阅读数 45 #HTML

当鼠标事件被触发时,pageX鼠标事件属性用于获取鼠标指针的水平坐标。坐标是相对于屏幕的。

示例

您可以尝试运行以下代码来了解如何实现pageX JavaScript 中的鼠标事件。

<!DOCTYPE html>
<html>
   <body>
      <p onclick = "coordsFunc(event)">
         Click here to get the x (horizontal) and y (vertical)
         coordinates of the mouse pointer.  
      </p>
      <script>
         function coordsFunc(event) {
            var x_coord = event.pageX;
            var y_coord = event.pageY;
            var xycoords = "X coords= " + x_coord + ", Y coords= " + y_coord;
            document.write(xycoords);
         }
      </script>
   </body>
</html>

以上就是pageX Mouse Event在JavaScript中的作用是什么?的详细内容,更多请关注IT视界其它相关文章!



热门