how to trigger a double click on a single click using jquery

后端 未结 2 685
一整个雨季
一整个雨季 2020-12-12 00:50

Is it possible to trigger double click on user\'s single click? note that I want the same behaviour as it was double clicked by using mouse, Is it possible to get the same b

相关标签:
2条回答
  • 2020-12-12 01:27

    Just an update on why. I use agent ransack and if I can launch it with a double-click I get two instances of the program. I can use different search parameters on each.

    0 讨论(0)
  • 2020-12-12 01:38

    Not sure where exactly your problem is, but this code works exactly as expected:

    $("#container").dblclick(function() { 
      //code executed on jQuery double click rather than mouse double click
      alert('dblclick');
    });
    $("#container").click(function() { 
      alert('click');
      $(this).dblclick(); 
    });
    
    $("#container2").click(function() { 
      $("#container").click();
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <div id="container">click 1</div>
    <div id="container2">click 2</div>

    If you click on 'click 1' - you will have the 2 alerts (the original and the dblclick).
    If you click on 'click 2' - the jquery will trigger the click on the first element, which will trigger 2 alerts (the click and the dblclick).

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