In the event bindings for jquery, you can trigger two click events (clicks) When you perform a double-click event (DblClick). That is, a tag element (such as a Div, and so on), if the element is bound at the same time by clicking Event (click) and double-click event (DblClick), the double-click event (DblClick) is not triggered, and the double-click event (DblClick) is executed. The two-click event is triggered.
Let's take a look at the execution order of the Click events:
Click: Mousedown,mouseout,click;
Double-click (DblClick): Mousedown,mouseout,click, Mousedown,mouseout,click,dblclick;
In a double-click event (DblClick), the two-click event that is triggered (clicking), the first click event is masked out, but not the second time. That is, a double-click event (DblClick) Returns the result of a single clicking event and a double click event (DblClick). Instead of a double-click event (DblClick) result and two click event Results (clicks).
In this case, the problem is solved by simply eliminating the extra click event.
SetTimeout
In jquery's $ (document). Ready (function () {}), write directly inside:
Defining SetTimeout Execution methods
var timefn = null;
$ (' div '). Click (function () {
Cancels the method that was not executed last time delay
Cleartimeout (TIMEFN);
Execution delay
Timefn = SetTimeout (function () {
Do function writes the code here to execute the Click event
},300);
});
$ (' div '). DblClick (Functin () {
Cancels the method that was not executed last time delay
Cleartimeout (TIMEFN);
Double-click the execution code of the event
})
From the test results, if the time of two clicks is around 300ms, it is still easy to see the click and DblClick events being called simultaneously, and if the interval is shorter or longer, there will only be a click or DblClick event.
At this point, you can avoid triggering a click when you double-click (DblClick) to some extent.
JQuery Double click event (DblClick) does not trigger a click event