1.

 1 <%@ page language="java" contentType="text/html; charset=UTF-8"
 2     pageEncoding="UTF-8"%>
 3 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 4 <html>
 5     <head>
 6         <meta http-equiv="Content-Type" content="text/html;charset=utf-8">
 7         <title>KeyCode Demo</title>
 8         <style type="text/css">
 9             
10         </style>
11         <script src="jquery-1.5.2.js" type="text/javascript"></script>
12         <script type="text/javascript">
13             $(document).ready(function(){
14                 //keypress 事件与 keydown 事件类似。当按钮被按下时,会发生该事件。它发生在当前获得焦点的元素上。
15                 $('.infobox').keypress(function(event){
16                     //确定被按下的键的数字代码
17                     $('p').text('Character typed is ' + event.keyCode + ' Corresponding character is: ' + String.fromCharCode(event.keyCode));
18                     //类似的还有keyup keydown
19                 });
20             });
21         </script>
22         <body>
23             <input type="text" class="infobox" />
24             <p></p>
25         </body>
26 </html>

 

posted on 2017-01-21 21:58  Sharpest  阅读(199)  评论(0编辑  收藏  举报