触发鼠标事件时,pageX鼠标事件属性用于获取鼠标指针的水平坐标。坐标是相对于屏幕的。
您可以尝试运行以下代码,以了解如何在JavaScript中实现pageX Mouse事件。
<!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>