使用js 设置组合快捷键
使用js设置快捷键的本质就是获得你要设置的这个键的keyCode 的值,如果要加ctrl,alt,shift,那么就添加一个ctrlkey,altKey,shiftKey来判断下,所以关键在于获取keycode的值。
(1) 设置 ctrl +enter 提交
1 if (e.ctrlKey && e.keyCode == 13){
2 returnsubmit();
3 }
(2) 设置 Alt+ 方向键 ←提交
1 if (e.altKey&& e.keyCode == 37){
2 returnsubmit();
3 }
(3) 设置 shift+F10 提交
1 if (e.shiftKey&& e.keyCode == 37){
2 returnsubmit();
3
4 }
(4) 设置enter 提交
1 if (e.keyCode == 13){
2 returnsubmit();
3 }
一些常见的快捷键的KeyCode:
1 keycode 8 =BackSpace BackSpace2 keycode 9 =Tab Tab3 keycode 12 =Clear4 keycode 13 =Enter5 keycode 16 =Shift_L6 keycode 17 =Control_L7 keycode 18 =Alt_L8 keycode 19 =Pause9 keycode 20 =Caps_Lock10 keycode 27 =Escape Escape11 keycode 32 =space space12 keycode 33 =Prior13 keycode 34 =Next14 keycode 35 =End15 keycode 36 =Home16 keycode 37 =Left17 keycode 38 =Up18 keycode 39 =Right19 keycode 40 =Down20 keycode 41 =Select21 keycode 42 =Print22 keycode 43 =Execute23 keycode 45 =Insert24 keycode 46 =Delete25 keycode 47 = Help
//当onkeydown 事件发生时调用hotkey函数
$("#CarNo").keydown(function (e) {
if (e.keyCode == 13)
{
alert("你按了键盘ENTER.");
}
});
原文:http://www.cnblogs.com/starksoft/p/5844551.html