项目经常会用到键盘快捷方式,需要使用键盘编码,下面根据网上找到的资料,整理如下:
<script type="text/javascript">
document.onkeydown = function(e){
e = e || window.event || arguments.callee.caller.arguments[0];
if(e && e.keyCode == 13){ //enter
//do something...
}
};
</script>
/* 键盘编码列表
8: BackSpace BackSpace 79: o O 133: F22
9: Tab Tab 80: p P 134: F23
12: Clear 81: q Q at 135: F24
13: Enter 82: r R 136: Num_Lock
16: Shift_L 83: s S 137: Scroll_Lock
17: Control_L 84: t T 187: acute grave
18: Alt_L 85: u U 188: comma semicolon
19: Pause 86: v V 189: minus underscore
20: Caps_Lock 87: w W 190: period colon
27: Escape Escape 88: x X 192: numbersign apostrophe
32: space 89: y Y 210: plusminus hyphen macron
33: Prior 90: z Z 211:
34: Next 96: KP_0 KP_0 212: copyright registered
35: End 97: KP_1 KP_1 213: guillemotleft guillemotright
36: Home 98: KP_2 KP_2 214: masculine ordfeminine
37: Left 99: KP_3 KP_3 215: ae AE
38: Up 100: KP_4 KP_4 216: cent yen
39: Right 101: KP_5 KP_5 217: questiondown exclamdown
40: Down 102: KP_6 KP_6 218: onequarter onehalf threequarters
41: Select 103: KP_7 KP_7 220: less greater bar
42: Print 104: KP_8 KP_8 221: plus asterisk asciitilde
43: Execute 105: KP_9 KP_9 227: multiply division
45: Insert 106: KP_Multiply KP_Multiply 228: acircumflex Acircumflex
46: Delete 107: KP_Add KP_Add 229: ecircumflex Ecircumflex
47: Help 108: KP_Separator KP_Separator 230: icircumflex Icircumflex
48: 0 equal braceright 109: KP_Subtract KP_Subtract 231: ocircumflex Ocircumflex
49: 1 exclam onesuperior 110: KP_Decimal KP_Decimal 232: ucircumflex Ucircumflex
50: 2 quotedbl twosuperior 111: KP_Divide KP_Divide 233: ntilde Ntilde
51: 3 section threesuperior 112: F1 234: yacute Yacute
52: 4 dollar 113: F2 235: oslash Ooblique
53: 5 percent 114: F3 236: aring Aring
54: 6 ampersand 115: F4 237: ccedilla Ccedilla
55: 7 slash braceleft 116: F5 238: thorn THORN
56: 8 parenleft bracketleft 117: F6 239: eth ETH
57: 9 parenright bracketright 118: F7 240: diaeresis cedilla currency
65: a A 119: F8 241: agrave Agrave atilde Atilde
66: b B 120: F9 242: egrave Egrave
67: c C 121: F10 243: igrave Igrave
68: d D 122: F11 244: ograve Ograve otilde Otilde
69: e E EuroSign 123: F12 245: ugrave Ugrave
70: f F 124: F13 246: adiaeresis Adiaeresis
71: g G 125: F14 247: ediaeresis Ediaeresis
72: h H 126: F15 248: idiaeresis Idiaeresis
73: i I 127: F16 249: odiaeresis Odiaeresis
74: j J 128: F17 250: udiaeresis Udiaeresis
75: k K 129: F18 251: ssharp question backslash
76: l L 130: F19 252: asciicircum degree
77: m M mu 131: F20 253: 3 sterling
78: n N 132: F21 254: Mode_switch
*/