1、结论:
- 相同点:当按钮被按下时,会发生该事件,发生在当前获得焦点的元素上。
- 输入中文区别较大,试一试
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<form action="">
<input type="text" class="text1"/>
<span>0</span>
</form>
<form action="">
<input type="text" class="text2"/>
<span>0</span>
</form>
</body>
<script src="libs/jquery-1.8.3.min.js"></script>
<script type="text/javascript">
$(function(){
var i = 0;
$(".text1").keydown(function(){
$(this).next().text(i+=1);
});
var j = 0;
$(".text2").keypress(function(){
$(this).next().text(j+=1);
});
//输入中文时有区别
})
</script>
</html>