【发布时间】:2008-09-27 14:54:36
【问题描述】:
我正在编写一些需要触发click 事件以获取链接的JavaScript 代码。在 Internet Explorer 中我可以做到这一点
var button = document.getElementById('myButton');
button.click();
但这在 Firefox 中不起作用,我假设任何其他浏览器。在 Firefox 中,我已经这样做了
var button = document.getElementById('myButton');
window.location = button.href;
我觉得这不是最好的方法。有没有更好的方法来触发click 事件?最好是不管元素类型或浏览器如何都能正常工作的东西。
【问题讨论】:
标签: javascript