JQuery double-click your mouse to solve conflicts

Transfer Links: https://www.shuzhiduo.com/A/xl560MKrzr/

In jQuery event binding, if the element is binding on click event (click) and double-click event (dblclick), then execute the click event (click), double-click will not trigger event (dblclick), perform double-click event ( dblclick) Shique will trigger twice click event (click).

html code:

<button>点击</button>

JQ Code:

<Script> 
        $ ( function () {
             // write jQuery code associated 
            // single double click interval is 300ms 
            // do first click twice an interval of less than a double click 300ms 
            var Timer = null ; 
 
            // Get event source, tie given event 
            $ ( 'Button') the Click (. function () {
                 // Clear timer 
                the clearTimeout (timer);
                 // set the timer-time 300ms timer 
                timer = the setTimeout ( function () { 
                    the console.log ( 'single' ); 
                }, 300 ) 
            });
 
            $ ( 'Button') DblClick (. Function () {
                 // Clear Timer 
                the clearTimeout (Timer); 
                the console.log ( 'double click' ); 
            }) 
        })
     </ Script>

 

Guess you like

Origin www.cnblogs.com/myitnews/p/12079590.html