pageX 滑鼠事件在 JavaScript 中承擔什麼角色?
觸發滑鼠事件時,使用 pageX 滑鼠事件屬性來獲取滑鼠指標的水平座標。該座標相對於螢幕。
示例
你可以嘗試執行以下程式碼,瞭解如何在 JavaScript 中實現pageX 滑鼠事件。
<!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>
廣告