Keyboard 事件

onkeydown: 在用户按下按键时触发。

onkeypress: 在用户敲击按钮时触发。

onkeyup: 当用户释放按键时触发。

 

示例

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>KeyCode</title>
    <script src="https://files.cnblogs.com/files/huey/jquery-1.8.3.min.js" type="text/javascript"></script>
</head>
<body>
    <input type="text" id="input_id">
    <script type="text/javascript">
        $("#input_id").keyup(function() {
            var keyCode = event.which || event.keyCode;
            if(keyCode == 13) {
                console.log($("#input_id").val());
                $("#input_id").val("");
            }
        });
    </script>    
</body>
</html>

 

KeyCode

HTML - 键盘事件

相关文章:

  • 2021-10-07
  • 2021-08-08
  • 2021-12-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
  • 2021-12-09
  • 2021-11-27
相关资源
相似解决方案