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>

更新於: 2020年5月23日

160 次瀏覽

開啟您的職業

完成課程並透過認證

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