Double-click and click event conflict resolution, and click event resolution.

Source: Internet
Author: User

Double-click and click event conflict resolution, and click event resolution.

Double-click and click event conflict resolution:
For click events and double-click events, it is very simple to take them out separately. For more information, see the click events of jQuery and the dblclick events of jQuery, however, if a single element is bound with both a click event and a double-click event, a conflict occurs. For example, if you double-click the event to trigger a double-click event, the event must be clicked completely, the double-click event is triggered, and the click event is also triggered. The following Code introduces how to solve the conflict problem through the code example. The Code is as follows:

<! DOCTYPE html> 

The code above solves the conflict between click and double-click. Only one event is triggered when you click or double-click the button.
I. Implementation principle:
The principle is actually simple, that is, to delay the execution of related code in the event processing function (not to say that the event is not triggered), that is, when the button is clicked for the first time, if the second click is not performed within 300 milliseconds, it is considered as a click event, and then the relevant code is executed. If the second click is performed within 300 milliseconds, the execution of the time-based function will be canceled. clicking the relevant code in the event processing function will not be executed, and only the code in the double-click event processing function will be executed.
Ii. Related reading:
1. For details about bind (), refer to the bind () method section of jQuery.
2. For details about the clearTimeout () function, refer to clearTimeout () method 1 of the window object.
3. For the setTimeout () function, see setTimeout () method 1 of the window object.
4. For details about the append () function, refer to the append () method section of jQuery.

The original address is: http://www.softwhy.com/forum.php? Mod = viewthread & tid = 13135.

For more information, see: http://www.softwhy.com/jquery/

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.