JavaScript double-click event cancels the default two-click event

Source: Internet
Author: User

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

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.