什麼是 JavaScript 中的 onkeydown 事件?


當按下按鍵時會觸發 onkeydown 事件。你可以嘗試執行以下程式碼,瞭解如何在 JavaScript 中使用 onkeydown 事件 −

示例

<html>
   <head>
      <script>
         <!--
            function sayHello() {
               alert("A key is pressed.")
            }
         //-->
      </script>
   </head>
   <body>
      <input type = "text" onkeydown = "sayHello()">
   </body>
</html>

更新於: 2020 年 6 月 19 日

306 人看過

開啟你的 職業生涯

透過完成課程獲得認證

開始
廣告
© . All rights reserved.