How do I double-click on objects using javascript? Do I have to .click() twice?

前端 未结 3 1934
天涯浪人
天涯浪人 2021-01-03 01:45

I tried searching for this but the only results that come up are on double click, and never how to automatically double click on something. (trigger a doubl

相关标签:
3条回答
  • 2021-01-03 02:03

    With jquery dblclick method you can that very easily. Some thing like.

    $("p").dblclick(function(){
       alert("The paragraph was double-clicked.");
    });
    

    see following link for more information

    http://www.w3schools.com/jquery/event_dblclick.asp

    http://api.jquery.com/dblclick/

    and If you are using javascript then see following link.

    Javascript Double Click Event

    0 讨论(0)
  • 2021-01-03 02:03
    document.getElementById("something").ondblclick = function(){
           alert("The paragraph was double-clicked.");
    }
    
    0 讨论(0)
  • 2021-01-03 02:18

    Dispatch a dblclick event like so:

    var targLink    = document.getElementById ("something");
    var clickEvent  = document.createEvent ('MouseEvents');
    clickEvent.initEvent ('dblclick', true, true);
    targLink.dispatchEvent (clickEvent);
    


    You can see the code in action at jsFiddle.

    0 讨论(0)
提交回复
热议问题