How to simulate a mouse click using JavaScript?

后端 未结 7 1090
无人及你
无人及你 2020-11-22 00:57

I know about the document.form.button.click() method. However, I\'d like to know how to simulate the onclick event.

I found this code somew

7条回答
  •  悲哀的现实
    2020-11-22 01:59

    JavaScript Code

       //this function is used to fire click event
        function eventFire(el, etype){
          if (el.fireEvent) {
            el.fireEvent('on' + etype);
          } else {
            var evObj = document.createEvent('Events');
            evObj.initEvent(etype, true, false);
            el.dispatchEvent(evObj);
          }
        }
    
    function showPdf(){
      eventFire(document.getElementById('picToClick'), 'click');
    }
    

    HTML Code

    
      
    

提交回复
热议问题