screenX 滑鼠事件在 JavaScript 中的作用是什麼?


觸發事件時,screenX 滑鼠事件將返回滑鼠指標的水平座標。

示例

你可以嘗試執行以下程式碼,瞭解如何在 JavaScript 中實現 screenX 滑鼠事件。

<!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.screenX;
            var y_coord = event.screenY;
            var xycoords = "X coords= " + x_coord + ", Y coords= " + y_coord;
            document.write(xycoords);
         }
      </script>
   </body>
</html>

更新於:23-05-2020

133 次瀏覽

啟動你的 事業

完成課程以獲得認證

開始
廣告