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/