一、键位扫描码,用event.keyCode获得
8 | | 退格 |
9 | | Tab |
12 | | 小键盘<5>,numlock未锁定时 |
13 | | 回车 |
16 | | Shift |
17 | | Ctrl |
18 | | Alt |
19 | | Pause Break |
20 | | CapsLock |
27 | | Esc |
33 | | PgUp |
34 | | PgDn |
35 | | End |
36 | | Home |
37 | | ← |
38 | | ↑ |
39 | | → |
40 | | ↓ |
45 | | Insert和小键盘的Ins |
46 | | Delete和小键盘的Del |
48 | | 0 ) |
49 | | 1 ! |
50 | | 2 @ |
51 | | 3 # |
52 | | 4 $ |
53 | | 5 % |
54 | | 6 ^ |
55 | | 7 & |
56 | | 8 * |
57 | | 9 ( |
65 | | A(小写一样) |
66 | | B |
67 | | C |
68 | | D |
69 | | E |
70 | | F |
71 | | G |
72 | | H |
73 | | I |
74 | | J |
75 | | K |
76 | | L |
77 | | M |
78 | | N |
79 | | O |
80 | | P |
81 | | Q |
82 | | R |
83 | | S |
84 | | T |
85 | | U |
86 | | V |
87 | | W |
88 | | X |
89 | | Y |
90 | | Z |
91 | | 左窗键 |
92 | | 右窗键 |
93 | | 仿右鼠标键 |
96 | | 0(小键盘) |
97 | | 1(小键盘) |
98 | | 2(小键盘) |
99 | | 3(小键盘) |
100 | | 4(小键盘) |
101 | | 5(小键盘) |
102 | | 6(小键盘) |
103 | | 7(小键盘) |
104 | | 8(小键盘) |
105 | | 9(小键盘) |
106 | | *(小键盘) |
107 | | +(小键盘) |
109 | | -(小键盘) |
111 | | /(小键盘) |
112 | | F1 IE占用 |
113 | | F2 |
114 | | F3 IE占用 |
115 | | F4 IE占用 |
116 | | F5 IE占用 |
117 | | F6 IE占用 |
118 | | F7 |
119 | | F8 |
120 | | F9 |
121 | | F10 |
取不到 | | F11 |
取不到 | | F12 |
取不到 | | Print Screen SysRq |
144 | | NumLock |
145 | | Scroll Lock |
186 | | : ; |
187 | | + = |
188 | | < , |
189 | | - _ |
190 | | > . |
191 | | ? / |
192 | | ` ~ |
219 | | { [ |
220 | | / |
221 | | } ] |
222 | | " ' |
二、检测同时按下的控制键用:
event.altKey true为按下了Alt键
event.ctrlKey true为按下了Ctrl键
event.shiftKey true为按下了Shift键
三、判断函数
//是否数字键
function isnumkey(nkey)
{
if(!event.altKey && !event.ctrlKey && !event.shiftKey &&
(nkey>=48 && nkey<=57 nkey>=96 && nkey<=105))
return true;
else
return false;
}
//是否字母键
function isalphakey(nkey)
{
if(!event.altKey && !event.ctrlKey && nkey>=65 && nkey<=90)
return true;
else
return false;
}
//是否字符键
function ischarkey(nkey)
{
if(!event.altKey && !event.ctrlKey && (nkey>=65 && nkey<=90
nkey>=48 && nkey<=57 nkey>=96 && nkey<=105 nkey==106
nkey==107 nkey==109 nkey==110 nkey==111
nkey>=186 && nkey<=192 nkey>=219 && nkey<=222))
return true;
else
return false;
}
--转自
该贴由koei123转至本版2015-7-14 11:05:50