jquery Combo Key Keyboard Event

Source: Internet
Author: User

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?
1 keydown();
2 keyup();
3 keypress();

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){
2 alert(event.keyCode);
3 });

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)
3 $("form").submit();
4 })
jQuery keyboard keycode

jquery Combo Key Keyboard Event

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.