How can I trigger a JavaScript event click

后端 未结 9 2046
迷失自我
迷失自我 2020-11-22 02:56

I have a hyperlink in my page. I am trying to automate a number of clicks on the hyperlink for testing purposes. Is there any way you can simulate 50 clicks on the hyperlink

9条回答
  •  攒了一身酷
    2020-11-22 03:51

    What

     l.onclick();
    

    does is exactly calling the onclick function of l, that is, if you have set one with l.onclick = myFunction;. If you haven't set l.onclick, it does nothing. In contrast,

     l.click();
    

    simulates a click and fires all event handlers, whether added with l.addEventHandler('click', myFunction);, in HTML, or in any other way.

提交回复
热议问题