Home > Web Front-end > JS Tutorial > body text

jquery adds shortcut keys to the page example_jquery

WBOY
Release: 2016-05-16 17:01:48
Original
924 people have browsed it

Copy code The code is as follows:

$(document).keydown(function(e){
if(e.which == 37) {
alert("left");
}
if(e.which == 39) {
alert("right");
}
});

In addition, there is a keypress event that is similar to the keydown event, but cannot be mixed. The difference between keydown and keypress is:

1 Only character keys can trigger the keypress event, and any key can trigger the keydown event. For example: F1-F12, direction keys, etc. can only use keydown.

2 keydown returns the keyboard code, keypress returns the ASCII character, taking the 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.shiftKey, e.ctrlKey

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!