Home » JavaScript » The solution with a DOM element under the double c...

The solution with a DOM element under the double click event coverage

When

wrote another JS, he found a problem:



$("#button1"), ".On" ("dbclick", "function"), {
/ / double-click event
} (.On) (click), function () {
/ / click event
});





encountered the above case, click the event will double click event overwrite, find a solution on the Internet, after the experiment feasible:




var clickTimes=0; / / record clicks
$("#button1"), ".On" ("click", function () {
ClickTimes++; / / record clicks
If (clickTimes==2) / / when you click on the number of 2
{
/ / double-click event
ClickTimes=0; / / remember cleared
}
 / / set a delay event
SetTimeout (function () {
If (clickTime==1)
{
/ / click event
ClickTimes=0; / / reset
}
}, 250);
})






idea: if the number of hits is 2, double-click the event;


if the number of hits is not 2, click event:


sets a 1/4 second delay event,


if you don't have clickTimes 1 after 1/4 seconds, click event



copyright notice: This article is original article for blogger. Without permission from blogger,.

must not be reprinted

Latest