当用户松开 HTML 中的键时执行脚本?


使用 onkeyup 属性。onkeyup 属性在用户释放键时触发。

示例

你可尝试运行以下代码,以便在释放键时执行脚本 -

<!DOCTYPE html>
<html>
   <body>
      <p>Press a key inside the textbox.</p>

      <input type = "text" onkeydown = "display()">

      <script>
         function display() {
            alert("You released a key!");
         }
      </script>
   </body>
</html>

更新于:2020年3月3日

102 次浏览

开启你的 职业生涯

通过完成课程获得认证

开始
广告
© . All rights reserved.