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

后端 未结 2 695
一整个雨季
一整个雨季 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: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();
    });
    
    
    click 1
    click 2

    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).

提交回复
热议问题