Home >Web Front-end >JS Tutorial >javascript onkeydown,onkeyup,onkeypress,onclick,ondblclick_javascript技巧

javascript onkeydown,onkeyup,onkeypress,onclick,ondblclick_javascript技巧

WBOY
WBOYOriginal
2016-05-16 18:56:231595browse

Here is a test code:



The test result is:
keydown
keypress
keyup
Obviously, the order of events occurs It is: keydown --> keypress --> keyup
When you press and hold a key for a period of time and then release it, the result is:
keydown
keypress
keydown
keypress
keydown
keypress
keydown
keypress
...
keyup
n keydown and n keypress, 1 keyup, the time interval set by the system.
About click and dblclick
Some time ago, a friend in the group asked a question about click and dblclick. I will also sort it out here. His request is that click and dblclick have different event handlers, but if dblclick is triggered, click will not be processed. Process. How to solve it?
Let’s first take a look at the occurrence of the event. The test code is as follows:



The result when double-clicked is as follows:
click
dblclick
When slowing down the click speed, the results are as follows:
click
click
click
It can be seen that when dblclick, a click event will be triggered first, and then if set in the system If there is a second click event within the double-click delay time range, it is considered a dblclick event.
So how to solve the problem raised by this friend? The code is given as follows:




The double-click test results are as follows:
dblclick
dblclick dblclick dblclick
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn