我正在使用以下代码提交表单:
element.dispatchEvent(new Event("submit"));
检查器返回错误:
Object doesn't support this action
这适用于 Chrome。
此命令的目的是在单击时使一个部门调用表单上的提交事件。
Jquery 不是一个选项
最佳答案
考虑到 future 的变化,这是使其适用于 IE11 和其他浏览器的最佳方式。
var event;
if(typeof(Event) === 'function') {
event = new Event('submit');
}else{
event = document.createEvent('Event');
event.initEvent('submit', true, true);
}
$el.dispatchEvent(event);
关于javascript - Chrome 中的 dispatchEvent 但 IE11 中没有,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27176983/