我正在编写一些需要click为链接触发事件的JavaScript代码.在Internet Explorer中,我可以这样做
var button = document.getElementById('myButton');
button.click();
Run Code Online (Sandbox Code Playgroud)
但这在Firefox中不起作用,我假设任何其他浏览器.在Firefox中,我做到了这一点
var button = document.getElementById('myButton');
window.location = button.href;
Run Code Online (Sandbox Code Playgroud)
我觉得这不是最好的方法.有没有更好的方法来触发click事件?优选地,无论元素类型或浏览器如何都可以工作.
javascript ×1