Home > Article > Web Front-end > Detailed explanation of the use of jquery keydown event
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); });
$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(); } });
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!