When an element has both a click and double-clicking event, a double-click triggers 2 clicks and 1 This double-click event.
Double-click: The 1th time, the 2nd and double-click events are triggered.
<! DOCTYPE html>varID; Window.onload=function() {document.getElementById (' Divdemo '). onclick =function () { //clears the 2nd Click event ID of the double-clicked eventCleartimeout (ID);//This code is placed below the settimeout, also the following timer is turned off. id = setTimeout (function() {//regardless of the single-click, a timer ID is immediately generated for each click, and the resulting ID is not related to whether the timer executes or not. alert (ID);//Click action}, 300); //cleartimeout (ID);} document.getElementById (' Divdemo '). ondblclick =function () { //clears the 1th Click event ID of the double-clicked eventcleartimeout (ID); alert (ID);//Double-click action } } </script>Only Click,
<script type= "Text/javascript" >varID; Window.onload=function() {document.getElementById (' Divdemo '). onclick =function () { //clears the 2nd Click event ID of the double-clicked event //cleartimeout (ID);//This code put settimeout below, also turn off the following timer. id = setTimeout (function() {//regardless of the single-click, a timer ID is immediately generated for each click, and the resulting ID is not related to whether the timer executes or not. alert (ID);//Click action}, 300); Cleartimeout (ID);//Only this can be placed when clicked, so that the click event does not execute } } </script><body> <div id= "Divdemo" style= "width:400px; height:400px; Background-color:red "> </div></body>JavaScript double-click event cancels the default two-click event