当按下键盘按钮时会发生 jQuery keypress() 事件方法。此事件类似于 keydown() 事件方法。 

语法

$(selector).keypress(function)

参数

参数说明
function是可选参数。触发按键时触发执行的函数。

例子

<!DOCTYPE html>
<html>
<head>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
<script>
i = 0;
$(document).ready(function(){
    $("input").keypress(function(){
        $("span").text (i += 1);
    });
});
</script>
</head>
<body>
请输入:<input type="text">
<p> 按键:<span>0</span></p>
</body>

</html>