Keyboard event KeyDown keypress KeyUp Difference

Source: Internet
Author: User

After testing, it is clear that the order in which the events are executed is: keydown->keypress->keyup.

But press a button continuously, will always trigger: KeyDown keypress. The KeyUp will be triggered until you lift the button.

But for some special keys, the events that can be triggered in the browser are different.

There are a few points to note:

1. Like keypress: The input of non-characters such as the shift CTRL key is not triggered.

2. When the Enter key encounters a form form, when there is only one text box and enter enter, the form is automatically submitted, which only triggers keydown,keypress two events.

3. When listening to the KeyDown event, the Enter key encounters a form form and target= ' _blank ' when some browsers intercept the page because:

Because KeyDown in the press to enter the time has been triggered, but then the program is still processing logic, in the processing of the submission, the browser will be considered to be the program opened a new page, not considered the user behavior opened, causing the browser to block the opening of new pages, The solution is: Switch the monitoring KeyDown to monitor keypress.

Summarize:

KeyDown from the performance point of view is to press any key. The event that is generated before the text box is not displayed to the text box if the character is pressed. KeyDown is triggered when a key is pressed.

KeyPress occurs when the key is released, and the character is entered into the text box. Keys that are pressed and released with an input character will be triggered.

Keyboard event KeyDown keypress KeyUp Difference

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.