Jquery adds examples of shortcuts to pages
- 2020-03-30 01:36:29
- OfStack
$(document).keydown(function(e){
if(e.which == 37) {
alert(" On the left ");
}
if(e.which == 39) {
alert(" right ");
}
});
There is also a keypress event that is similar to the keydown event, but cannot be mixed. The difference between keydown and keypress is:
Keypress event can only be triggered by a character key, and keydown event can be triggered by any key, such as: f1-f12, direction key, etc. Keydown can only be used.
2 keydown returns the code of the keyboard, keypress returns the ASCII character, take character a as an example, keydown returns 65, and keypress returns 97.
If you want to detect Ctrl, Shift, and other key combinations to determine whether these objects are true: e.hiftkey, e.c.trlkey