Example, usage of jquery keyboard event and enter key event.
// Keyboard events
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 pressed. Triggered when released, that is, the event after you press the keyboard and lift it up
3. keypress()
The keypress event will be triggered when the key is tapped. We can understand it as pressing and lifting the same key
//Enter key event
// Bind Define keyboard press event
$(document).keypress(function(e) {
// Enter key event
if(e.which == 13) {
jQuery(".confirmButton ").click();
} }
});
//Up and down key event
$(document).keydown(function(event){
//Judge when event.keyCode When it is 37 (i.e., the left side key), execute the function to_left();
//Judge when event.keyCode is 39 (i.e., the right side key), execute the function to_right();
if( event.keyCode == 37){
to_left();
}else if (event.keyCode == 39){
to_right();
}
});
Note: Due to the different keyboard press events of browsers, some events may not operate normally, so it is recommended to operate the keydown event!
Jquery monitors keys and presses the Enter key to trigger a method
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31