JavaScript learning notes (6) Enable onDbClick to not trigger onClick events when onDbClick is triggered by latency

Source: Internet
Author: User
By default, a click event is triggered when you double-click an event, but this is sometimes not what we want, so how can we block the trigger of the click event when double-clicking? There is a method to delay execution circulating on the Internet. The general idea is as follows: by default, when double-clicking an event, the click event is triggered, but sometimes this is not what we want, so how can we block the trigger of the click event when double-clicking? There is a method of delayed execution circulating on the Internet. The general idea is as follows:
1. Declare a global timer variable such as clickTimer.
2. Set the timer in the event clicked by the proxy. The default setting is 220 milliseconds, which triggers the real click event processing function.
3. Judge the timer variable in the double-click event. If the variable is not NULL, it indicates that the click event is triggered before the double-click event is triggered to cancel the timer, because the real click event processing function is triggered after 220 milliseconds, when the timer is completed, the real click event processing function will not be executed.

Code attached:
1var timerClick = null;
2 // Click Event proxy
3 function _ onNodeClick (id ){
4 // onNodeClick is the real Click Event Processing Function
5 timerClick = window. setTimeout ("onNodeClick ('" + id + "')", 220 );
6}
7 // double-click the event processing function
8 function _ onNodeDbClick (id ){
9 if (timerClick ){
10 window. clearTimeout (timerClick );
11}
12}

The above content does not trigger the onClick event when onDbClick is triggered by latency. For more information, see www.php1.cn)

Related Article

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.