Use the time picker to differentiate between clicks and double clicks on a Web page

Source: Internet
Author: User

On the Web page, click the event that contains the Onmousedown,onmouseup,onclick process once. Similarly, the double-click event contains the Onmousedown,onmouseup,onclick,onmousedown,onmouseup,onclick,ondblclick process. Therefore, the onclick is also triggered when the ondblclick trigger is triggered on the Web page, so we need to distinguish them when we register the 2 events in the same element. The following uses delay processing to differentiate.

<script type= "Text/javascript" >

When we click, we want to only execute Clickalert

When we double-click, we want to only execute Dblclickalert

var timer;
$ (". Test"). On ("click", Function () {
Cleartimeout (timer);
Timer = SetTimeout ("Clickalert ()", 300); Processing that is clicked is delayed by 0.3 seconds
}). On ("DblClick", function () {
Cleartimeout (timer);
Dblclickalert ();
});

Click the thing you want to do
function Clickalert () {
Alert ("click Now");
}

Double-click the thing you want to do
function Dblclickalert () {
Alert ("Double-click now");
}
</script>

Use the time picker to differentiate between clicks and double clicks on a Web page

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.