jQuery deal with keyboard events, such as the novel on the site of the common key to achieve the previous article and the next article, press CTRL + ENTER to achieve form submission, Google Reader and Youdao reading in the full shortcut key operation ...
This paper describes the principle and method of jquery handling keys.
jquery handles keyboard events with three functions, depending on the order in which the events occur:
View Source print?
KeyDown ()
The KeyDown event is triggered when the keyboard is pressed and can return false in the bound function to prevent the browser from triggering the default event.
KeyUp ()
The KeyUp event is triggered when the key is released, which is the event you press the keyboard up
KeyPress ()
The KeyPress event is triggered when the button is tapped, and we can understand that pressing and lifting the same button
How can we get the A or Z or the return button I pressed?
Keyboard events can pass a parameter event, in fact, some jquery event function can pass such a parameter
View Source print?
1 |
$( ‘input‘ ).keydown( function (event){ |
In the above code, event. keycode can help us get to what button we pressed, he returned the ASCII code, such as the next key, 38,40,37,39
If we want to implement Ctrl+enter is CTRL + ENTER submit Form
View Source print?
1 |
$(document).keypress( function (e) { |
2 |
if (e.ctrlKey && e.which == 13) |
jQuery
keyboard
keycode
jquery Combo Key Keyboard Event