The same element of JavaScript binds the click and dblclick events at the same time (Click and double-click events at the same time)

Source: Internet
Author: User

In principle, do not bind a click or double-click event to the same Dom element, which may inevitably affect each other.

I encountered the following problem: a click and dblclick (jquery used) are bound to the same Dom element. In Firefox, double-click events are triggered sometimes, but sometimes they do not, conjecture may be caused by the impact of the Click Event (double-click the event under IE to trigger ). Baidu has some content: IE handles double-click events differently from other browsers

Double-click trigger event under ie:

Mousedown, mouseup, click, mouseup, dblclick

In FF:

Mousedown, mouseup, click, mousedown, mouseup, click, dblclick

However, you only need to remember a status when you click it and reset the status for a timer. If a click trigger occurs before the timer reset status, you can call the double-click event processing function.

Clickinterval = 600;

Clicked = false;

Cleartimeout (clicktimer );

Clicktimer = setTimeout (function (){
// Alert ("clicktime:" + clicktime );
Clicked = false;
// Clicktime = 0;
}, Clickinterval );

If (clicked)

// Dblclicked event

Clicked = true;

The above code has a problem under IE, because IE triggers only one clicked when double-clicking (three clicks, ie will have double-clicking effect). However, only the browser type is determined, and a double-click event is bound. Determine if jquery $. browser. MSIE is used in IE (true or false is returned)

Related Article

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.