实例 演示如何使用 event.which 确定按下哪个键

x
 
<!DOCTYPE html>
<html>
<head>
<script src="https://libs.baidu.com/jquery/2.1.4/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("input").keydown(function(event){ 
    $("div").html("Key: " + event.which);
  });
});
</script>
</head>
<body>
Enter your name: <input type="text">
<p>When you type in the field above, the div element below will display the key number.</p>
<div></div>
</body>
</html>
                    

输出结果