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


shiftKey 滑鼠事件屬性用於顯示在單擊滑鼠按鈕時是否按下 SHIFT 鍵。

示例

可以嘗試執行以下程式碼來學習如何使用 JavaScript 實現shiftKey 滑鼠事件。

<!DOCTYPE html>
<html>
   <body onmousedown = "funcShiftKey(event)">
      <div>Press and hold SHIFT key and then click here.</div>
      <script>
         function funcShiftKey(event) {
            if (event.shiftKey) {
               alert("SHIFT key: Pressed");
            } else {
               alert("SHIFT key: NOT Pressed");
            }
         }
      </script>
   </body>
</html>

更新於: 23-5-2020

160 次瀏覽

啟動你的職業生涯

透過完成課程獲得認證

開始學習
廣告
© . All rights reserved.