How to dispatch a double click event on an element?

前端 未结 3 1375
情深已故
情深已故 2021-01-13 01:04

I can dispatch a simple click event (without any optional parameters) with:

var clickEvt = document.createEvent(\"MouseEvents\");
clickEvt.initEvent(\"click\         


        
3条回答
  •  无人及你
    2021-01-13 01:42

    This worked in Chrome@83

    const event = new MouseEvent('dblclick', {
      bubbles: true,
      cancelable: true,
      view: window
    });
    
    const buttonEl = document.querySelector('#my-button');
    buttonEl.dispatchEvent(event);
    

提交回复
热议问题