Jquery events-Keyboard Events

Source: Internet
Author: User

Keyboard Events are used to process all users' keyboard hits, whether inside or outside the text input area. Keyboard Events have different scopes in different browsers. Generally, these keyboard events can be applied to elements such as form, a tag, window, and document. The keyboard event can be triggered on all the elements that can obtain the intersection, and the elements that can obtain the focus can be understood in this way, when the tab key is used, the elements that can be jumped to are the elements that can use the keyboard event (when the tabindex attribute value is not set for these elements, when the tabindex is set to a negative number, when the tab key is used, the focus is not obtained ).
A keyboard event can pass a parameter event. In fact, all jquery events can pass such a parameter. This event is an object and includes some attributes, when an event is triggered, you can use the event to obtain some event values. For example, you can use the event when using the keyboard. keycode to obtain the ASCII code of the key. See the following
1: The keydown () event is the first keyboard event triggered when the keyboard is clicked. If you continue to hold down the key bit, the keydown event will continue.
$ ('Input'). keydown (function (event ){
Alert (event. keycode );
});
The values returned by the keyboard can be used to control these elements. For example, the upper and lower left keys are:, 40, respectively.
2: The keypress () event is similar to the keydown event, with only one exception. If you want to block the default behavior of the key, you must be a keypress event.
3: The keyup () event is the last event (after the keydown event, this event is triggered only once after the keyboard is released (because releasing the keyboard is not a constant state ).
$ ('Input'). keyup (funciton (){
Alert ('keyup function is running !! ');
});
4: In jquery, The keydown, keypress, and keyup events are executed in a certain order.
$ ('Input'). keyup (function (){
Console. Log ('keyup ');
});
$ ('Input'). keydown (function (){
Console. Log ('keylow ');
});
$ ('Input'). keypress (function (){
Console. Log ('keypress ');
});
The execution result is: keydown, keypress, keyup.
Alert is not used here because some events will be blocked during alert, and the keyup event will be blocked here. to experiment with this code, you can do it in Firefox, you need to install the firebug plug-in the browser. Install Firefox with confidence because it is an open-source browser. I believe in open-source software.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.