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


ctrlkey 滑鼠事件屬性用於顯示滑鼠按鈕單擊時按下 CTRL 鍵與否。

示例

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

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

         }
      </script>
   </body>
</html>

更新於: 2020 年 5 月 23 日

162 次瀏覽

開始你的職業生涯

完成課程,獲得認證

立即開始
廣告