Here is a section of the test code:
<script type= "Text/javascript" >
Document.onkeydown = function () {
document.getElementById ("Test"). InnerHTML + = "keydown<br/>";
}
Document.onkeyup = function () {
document.getElementById ("Test"). InnerHTML + = "keyup<br/>";
}
document.onkeypress = function () {
document.getElementById ("Test"). InnerHTML + = "keypress<br/>";
}
</script>
<div id= "Test" ></div>
Test results are:
KeyDown
KeyPress
KeyUp
Obviously, the sequence of events occurs: KeyDown--> keypress--> KeyUp
When you hold down 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, System set time interval.
About Click and DblClick
Some time ago Group A friend asked a question about click and DblClick, here at the same time also tidy up, his request is click and DblClick have different event handlers, but if triggered DblClick then click Do not do processing. How to solve?
Let's take a look at the event and test the code as follows:
<script type= "Text/javascript" >
Document.onclick = function () {
document.getElementById ("Test"). InnerHTML + = "click<br/>";
}
Document.ondblclick = function () {
document.getElementById ("Test"). InnerHTML + = "dblclick<br/>";
}
</script>
<div id= "Test" ></div>
When you double-click, the results are as follows:
Click
DblClick
When you slow down the click Speed, the results are as follows:
Click
Click
Click
Visible, DblClick first triggers a click event, which is considered a DblClick event if there is a second click event within the double-click Delay time of the system setting.
So how do you solve this friend's question? The following code is given:
<script type= "Text/javascript" >
function Clicktest () {
document.getElementById ("Test"). InnerHTML + = "click<br/>";
}
function Dblclicktest () {
document.getElementById ("Test"). InnerHTML + = "dblclick<br/>";
}
Document.onclick = function () {
This.timeout = Window.settimeout (clicktest,300);
}
Document.ondblclick = function () {
if (this.timeout) window.cleartimeout (this.timeout);
Dblclicktest ();
}
</script>
<div id= "Test" ></div>
Double-click the test results as follows:
DblClick
DblClick
DblClick
DblClick
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