Home > Web Front-end > JS Tutorial > Detailed explanation of the use of jquery keydown event

Detailed explanation of the use of jquery keydown event

黄舟
Release: 2017-06-27 13:31:13
Original
1505 people have browsed it

jqueryKeyboardEvent introduction, friends who use jquery can refer to it.

1. The first thing you need to know is:
1. keydown()
The keydown event will be triggered when the keyboard is pressed.
2. keyup()
The keyup event will be triggered when the key is released, that is, the event after you press the keyboard and get up
3. keypress()
The keypress event will be triggered when the key is tapped. We can understand it as pressing and lifting. Press the same key

2. Get the corresponding ascII code on the keyboard:

$(
document
).keydown(function(event){ 
alert(event.keyCode); 
});
Copy after login

$tips: In the above example, event.keyCode can help us After getting the key we pressed on the keyboard, it returns the ascii code, for example, the up, down, left and right keys are 38, 40, 37, 39 respectively;

3. Example (when pressing When pressing the left and right keys on the keyboard)

The code is as follows:

$(document).keydown(function(event){ 
//判断当event.keyCode 为37时(即左方面键),执行
函数
to_left(); 
//判断当event.keyCode 为39时(即右方面键),执行函数to_
right
(); 
if(event.keyCode == 37){ 
to_left(); 
}else if (event.keyCode == 39){ 
to_right(); 
} 
});
Copy after login


4. TIPS:
This example is often used when browsing electronic photo albums. . .

The above is the detailed content of Detailed explanation of the use of jquery keydown event. For more information, please follow other related articles on the PHP Chinese website!

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