什么是 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.