[]jquery Double click event (DblClick) does not trigger a click event

Source: Internet
Author: User

Example 1: Link: http://www.w3school.com.cn/jquery/event_dblclick.asp

    • HTML Series Tutorials
    • Browser script
    • Server Scripts
    • ASP. NET Tutorial
    • XML Series Tutorials
    • Web Services Series Tutorials
    • Build Station Manual
JQuery Tutorials
    • JQuery Tutorials
    • About JQuery
    • JQuery Installation
    • JQuery syntax
    • JQuery Selector
    • JQuery Events
JQuery effect
    • JQuery Hide/Show
    • JQuery fades
    • JQuery Swipe
    • JQuery Animations
    • JQuery Stop ()
    • JQuery Callback
    • JQuery Chaining
JQuery HTML
    • JQuery get
    • JQuery settings
    • JQuery add
    • JQuery Delete
    • JQuery CSS Class
    • JQuery css ()
    • JQuery size
JQuery traversal
    • JQuery traversal
    • JQuery Ancestors
    • JQuery descendants
    • Fellow of JQuery
    • JQuery filtering
JQuery AJAX
    • Introduction to JQuery AJAX
    • JQuery load
    • JQuery Get/post
JQuery Misc
    • JQuery noconflict ()
JQuery instances
    • JQuery instances
    • JQuery Quiz
JQuery Reference Manual
    • JQuery Reference Manual
    • JQuery Selector
    • JQuery Events
    • JQuery effect
    • JQuery Document Operations
    • JQuery Property Operations
    • JQuery CSS Operations
    • JQuery Ajax
    • JQuery traversal
    • JQuery data
    • JQuery DOM Elements
    • JQuery Core
    • JQuery Properties
JQuery Event-DblClick () method

JQuery Event Reference Manual

Instance

When you double-click a button, the element is hidden or displayed:

$ ("button"). DblClick (function () {  $ ("P"). Slidetoggle ();});

Try it yourself.

Definition and usage

The DblClick event occurs when you double-click an element.

A click occurs when the mouse pointer rests over the element and then presses and releases the left mouse button.

A double click event occurs two times in a short period of time.

The DblClick () method triggers the DblClick event, or a function that runs when the DblClick event occurs.

Tip: If you apply the DblClick and click events to the same element, problems may arise.

Triggering the DblClick event syntax
$ (selector). DblClick ()

Try it yourself.

Bind a function to the DblClick event syntax
$ (selector). DblClick (function)
Parameters Description
function Optional. Specifies the function that runs when the DblClick event occurs.

Try it yourself.

JQuery Event Reference Manual

Example 2:

In the event bindings for jquery, you can trigger two click events (clicks) When you perform a double-click event (DblClick). That is, a tag element (such as a Div, and so on), if the element is bound at the same time by clicking Event (click) and double-click event (DblClick), the double-click event (DblClick) is not triggered, and the double-click event (DblClick) is executed. The two-click event is triggered.

  Let's take a look at the execution order of the Click events:

Click: Mousedown,mouseout,click;
Double-click (DblClick): Mousedown,mouseout,click, Mousedown,mouseout,click,dblclick;

In a double-click event (DblClick), the two-click event that is triggered (clicking), the first click event is masked out, but not the second time. That is, a double-click event (DblClick) Returns the result of a single clicking event and a double click event (DblClick). Instead of a double-click event (DblClick) result and two click event Results (clicks).

In this case, the problem is solved by simply eliminating the extra click event.

SetTimeout

In jquery's $ (document). Ready (function () {}), write directly inside:

//Defining SetTimeout Execution methods
var timefn =Null

$(‘Div'). Click (function () {
// Cancel the method that was not executed last time
Cleartimeout (TIMEFN);
// execution delay
Timefn = SetTimeout (function () {
//do Function here writes the code for the click event to execute
},300);
});

$ ( "div"). DblClick (Functin () {
// cancellation of methods not performed last delay
Cleartimeout (TIMEFN);
// Double-click the execution code of the event
})

From the test results, if the time of two clicks is around 300ms, it is still easy to see the click and DblClick events being called simultaneously, and if the interval is shorter or longer, there will only be a click or DblClick event.

At this point, you can avoid triggering a click when you double-click (DblClick) to some extent.

[]jquery Double click event (DblClick) does not trigger a 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.