dispatchEvent在IE11中不起作用 [英] dispatchEvent not working in IE11
本文介绍了dispatchEvent在IE11中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下代码提交表单:
I am using the following code to submit to a form:
element.dispatchEvent(new Event("submit"));
Inspector返回错误:
对象不支持此操作
Inspector returns the error: Object doesn't support this action
这适用于Chrome。
This works in Chrome.
此命令的目的是在单击时对窗体上的提交事件进行调用。
The purpose of this command is to make a division call the submit event on a form when clicked.
<强> Jquery的不是一个选项强>
推荐答案
这是使其适用于IE11和其他浏览器并考虑未来更改的最佳方法。
This is the best way to make it work for IE11 and other browsers with considering future changes.
var event;
if(typeof(Event) === 'function') {
event = new Event('submit');
}else{
event = document.createEvent('Event');
event.initEvent('submit', true, true);
}
$el.dispatchEvent(event);
这篇关于dispatchEvent在IE11中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文