js 키보드 버튼 검사 실현

17730 단어 자바 script
 1 DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
 2 <HTML>
 3 <HEAD>
 4     <TITLE>js     TITLE>
 5 HEAD>
 6 <BODY>
 7     <script type="text/javascript">
 8         var keystring = "";//        
 9         function $(s) { return document.getElementById(s) ? document.getElementById(s) : s; }
10         function keypress(e) {
11             var currKey = 0, CapsLock = 0, e = e || event;
12             currKey = e.keyCode || e.which || e.charCode;
13             CapsLock = currKey >= 65 && currKey <= 90;
14             switch (currKey) {
15                 //     、  、  、  、   、   
16                 case 8: case 9: case 13: case 32: case 37: case 38: case 39: case 40: case 46: keyName = ""; break;
17                 default: keyName = String.fromCharCode(currKey); break;
18             }
19             keystring += keyName;
20         }
21         function keydown(e) {
22             var e = e || event;
23             var currKey = e.keyCode || e.which || e.charCode;
24             if ((currKey > 7 && currKey < 14) || (currKey > 31 && currKey < 47)) {
25                 switch (currKey) {
26                     case 8: keyName = "[  ]"; break;
27                     case 9: keyName = "[  ]"; break;
28                     case 13: keyName = "[  ]"; break;
29                     case 32: keyName = "[  ]"; break;
30                     case 33: keyName = "[PageUp]"; break;
31                     case 34: keyName = "[PageDown]"; break;
32                     case 35: keyName = "[End]"; break;
33                     case 36: keyName = "[Home]"; break;
34                     case 37: keyName = "[    ]"; break;
35                     case 38: keyName = "[    ]"; break;
36                     case 39: keyName = "[    ]"; break;
37                     case 40: keyName = "[    ]"; break;
38                     case 46: keyName = "[  ]"; break;
39                     default: keyName = ""; break;
40                 }
41                 keystring += keyName;
42             }
43             $("content").innerHTML = keystring;
44         }
45         function keyup(e) {
46             $("content").innerHTML = keystring;
47         }
48         document.onkeypress = keypress;
49         document.onkeydown = keydown;
50         document.onkeyup = keyup;
51     script>
52     <input type="text" />
53     <input type="button" value="    " onclick="$('content').innerHTML = '';keystring = '';" />
54     <br /><span id="content">span>
55 BODY>
56 HTML> 

 
다음으로 전송:https://www.cnblogs.com/tl2f/p/5604813.html

좋은 웹페이지 즐겨찾기