index.jsp
1 <%@ page language="java" contentType="text/html; charset=GB18030" pageEncoding="GB18030"%>
2 <html>
3 <head>
4 <title>Event测试</title>
5 <script type="text/javascript" src="js/jquery-1.2.6.min.js"></script>
6 <script type="text/javascript" src="js/auto_full.js"></script>
7 </head>
8 <body>
9 <input type="text" name="word" id="word"/>
10 </body>
11 </html>
12
auto_full.js脚本
1 $(document).ready(function(){
2 //获取输入框
3 var wordInput = $("#word");
4 //给文本框添加按下并弹起事件
5 wordInput.keyup(function(e){
6 var currKey=0,CapsLock=0;
7 var e=e||event;
8 currKey=e.keyCode||e.which||e.charCode;
9 CapsLock=currKey >=65 && currKey <=90;
10 var keyCode=e['keyCode'];
11 if(keyCode>=65 && keyCode<=90 || keyCode==8 || keyCode==46){
12 alert(keyCode);
13 alert(String.fromCharCode(currKey));
14 }
15 });
16 });
源码下载