Triggering double click via jQuery or pure Javascript for a single click event

前端 未结 1 1430
情话喂你
情话喂你 2021-01-28 06:33

I want to trigger double click event on any element when a single click event occurs in that element.

To be more clear, let\'s say I have a text box with some text, and

相关标签:
1条回答
  • The code you provided above works for me. A double click is triggered when a single click occurs. I used this variation:

    var numd = 0; 
    $("#content").dblclick(function() { 
        numd++; 
    });
    $("#content").click(function() { 
        $(this).dblclick(); 
    });
    

    numd is incremented correctly.

    For multiple clicks:

    You could use a variable to keep track of which click you are on while using the click() method to perform clicks. Here is an example to trigger a triple click.

    var clicknum = 0;
    $("#text-box").click(function() {
        clicknum++;
        if (clicknum < 3) {
            $(this).click();
        }
        else {
            // Reset clicknum since we're done.
            clicknum = 0;
        }
    }
    
    0 讨论(0)
提交回复
热议问题