使用js 设置组合快捷键

使用js 设置组合快捷键

  使用js设置快捷键的本质就是获得你要设置的这个键的keyCode 的值,如果要加ctrl,alt,shift,那么就添加一个ctrlkey,altKey,shiftKey来判断下,所以关键在于获取keycode的值。

  (1) 设置 ctrl +enter 提交  

1 if (e.ctrlKey && e.keyCode == 13){  
2    return submit();  
3 }

  (2) 设置  Alt+ 方向键 ←提交

1 if (e.altKey&& e.keyCode == 37){  
2     return submit(); 
3 }

  (3) 设置  shift+F10 提交

1 if (e.shiftKey&& e.keyCode == 37){   
2    return submit();
3 
4 }

  (4) 设置enter 提交

1 if (e.keyCode == 13){
2  return submit();   
3 }

  一些常见的快捷键的KeyCode:

1 keycode    8 = BackSpace BackSpace
 2   keycode    9 = Tab Tab
 3   keycode   12 = Clear
 4   keycode   13 = Enter
 5   keycode   16 = Shift_L
 6   keycode   17 = Control_L
 7   keycode   18 = Alt_L
 8   keycode   19 = Pause
 9   keycode   20 = Caps_Lock
10   keycode   27 = Escape Escape
11   keycode   32 = space space
12   keycode   33 = Prior
13   keycode   34 = Next
14   keycode   35 = End
15   keycode   36 = Home
16   keycode   37 = Left
17   keycode   38 = Up
18   keycode   39 = Right
19   keycode   40 = Down
20   keycode   41 = Select
21   keycode   42 = Print
22   keycode   43 = Execute
23   keycode   45 = Insert
24   keycode   46 = Delete
25   keycode   47 = Help

<script type="text/javascript">

//当onkeydown 事件发生时调用hotkey函数
        $("#CarNo").keydown(function (e) {
            if (e.keyCode == 13)
            {
               alert("你按了键盘ENTER.");
            }
        });

</script>

posted @ 2016-09-06 09:45  StarkSoft  阅读(13566)  评论(0编辑  收藏  举报