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

jquery carriage return event implementation code_jquery

WBOY
Release: 2016-05-16 18:03:06
Original
1022 people have browsed it

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

Copy code The code is as follows:

//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

Copy code The code is as follows:

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!