JQuery Double click event (DblClick) does not trigger a click event

Source: Internet
Author: User

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

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.