获取键盘键值

来源:互联网 发布:java string 转list 编辑:程序博客网 时间:2024/04/28 21:57


<html>
<head>
<title>键盘事件测试</title>
<script src="http://www.w3school.com.cn/jquery/jquery-1.11.1.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("*").css("text-align","center");
  $("input").keydown(function(event){
    $("div").html("键值 Key: " + event.keyCode+" charCode:"+ event.charCode+"char:"+String.fromCharCode(event.keyCode)
      +" which:"+ event.which);
  });
});
</script>
</head>
<body>
<h2>获取键盘键值</h2>
请随意键入一些字符:<input type="text" />
<p>当您在上面的框中键入文本时,下面的 div 会显示键位序号。</p>
<div></div>

</body>
</html>

0 0
原创粉丝点击