Home > Article > Web Front-end > How to set the combined shortcut key/tabindex function in js_javascript skills
There are still many shortcut keys used in daily life, such as the familiar paste ctrl v and copy ctrl c. Using shortcut keys can improve the efficiency of our work, especially when we are familiar with an operation and use it again. The operation will become very convenient and smooth. For heavy keyboard users, the keyboard will always be faster than the mouse.
1) tabindex:
is to use tab to easily control links and form elements on the page
Its usage is very simple: obj.tabindex = tabindex; this tabindex The value, according to w3c regulations, can start from 0 and go to 32767
2) js setting combination shortcut keys
The essence is to get the keyCode value of the key you want to set. If you want to add ctrl, alt, shift, then add a ctrlkey , altKey, shiftKey to judge, so the key lies in the value of keycode
(1) Set ctrl enter to submit
if (e.ctrlKey && e.keyCode == 13){
return submit();
}
(2) Set the Alt direction key ←
if (e.altKey&& e.keyCode == 37){
return submit();
}
(3) Set shift F10
if (e.shiftKey&& e.keyCode == 37){
return submit( );
}
4) Set en
ter submit
if (e.keyCode == 13){
return submit();
}
Here are some common shortcut keys:
keycode 8 = BackSpace BackSpace
keycode 9 = Tab Tab
keycode 12 = Clear
keycode 13 = Enter
keycode 16 = Shift_L
keycode 17 = Control_L
keycode 18 = Alt_L
keycode 19 = Pause
keycode 20 = Caps_Lock
keycode 27 = Escape Escape
keycode 32 = space space
keycode 33 = Prior
keycode 34 = Next
keycode 35 = End
keycode 36 = Home
keycode 37 = Left
keycode 38 = Up
keycode 39 = Right
keycode 40 = Down
keycode 41 = Select
keycode 42 = Print
keycode 43 = Execute
keycode 45 = Insert
keycode 46 = Delete
keycode 47 = Help
Note: Browser compatibility Question