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


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

示例

你可以嘗試執行以下程式碼來學習如何在 JavaScript 中實現altKey 滑鼠事件。

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

更新於:2020 年 5 月 23 日

161 次瀏覽

開啟你的 職業

完成課程獲得認證

開始
廣告