Prevent click event from firing when dblclick event fires

前端 未结 12 1289
名媛妹妹
名媛妹妹 2020-12-02 20:17

I\'m handling both the click and dblclick event on a DOM element. Each one carries out a different command, but I find that when double clicking on the element, in addition

12条回答
  •  萌比男神i
    2020-12-02 20:48

    I know this is old as heck, but thought I'd post anyhow since I just ran into the same problem. Here's how I resolved it.

     $('#alerts-display, #object-display').on('click', ['.item-data-summary', '.item-marker'], function(e) {
        e.preventDefault();
    
        var id;
    
        id = setTimeout(() => {
           // code to run here
           return false;
        }, 150);
    
        timeoutIDForDoubleClick.push(id);
    });
    
    
    $('.panel-items-set-marker-view').on('dblclick', ['.summary', '.marker'], function(e) {
        for (let i = 0; i < timeoutIDForDoubleClick.length; i++) {
           clearTimeout(timeoutIDForDoubleClick[i]);
        }
    
        // code to run on double click
    
        e.preventDefault();
    });
    

提交回复
热议问题