[英]FireEvent in IE 11/Firefox
I have this situation of migration from IE 9 to 11 with added support for Firefox and one of my collegue has replaced 我有从IE 9迁移到11的情况,并增加了对Firefox的支持,而我的一位同事已替换了
form.fireEvent("onsubmit");
with the following block 与以下块
var event; // The custom event that will be created
if (document.createEvent) {
event = document.createEvent("HTMLEvents");
event.initEvent("submit", true, true);
form.dispatchEvent(event);
} else {
event = document.createEventObject();
event.eventType = "submit";
form.fireEvent("submit");
}
form.submit();
I couldn't understand what it means. 我不明白这是什么意思。 Also is the above block correct?
上面的方块也是正确的吗?
if (document.createEvent){}
Checking if this supported, since many method use to create custom event is depreciated 检查是否支持此方法,因为许多用于创建自定义事件的方法已弃用
event = document.createEvent("HTMLEvents");
if above is true then create Event
object 如果以上为true,则创建
Event
对象
HTMLEvents
is the type of event to be created. HTMLEvents
是要创建的事件的类型。 Check Here for more 在这里查看更多
event.initEvent("submit", true, true);
Defining the event name.Here the event name is "submit". 定义事件名称。这里的事件名称为“提交”。
Normal syntax is event.initEvent(type, bubbles, cancelable);
普通语法是
event.initEvent(type, bubbles, cancelable);
form.dispatchEvent(event)
;form.dispatchEvent(event)
;
dispatchEvent
is the last step of the create-init-dispatch process, which is used for dispatching events into the implementation's event model. dispatchEvent
是create-init-dispatch过程的最后一步,用于将事件分派到实现的事件模型中。 More about dispatchEvent 有关dispatchEvent的更多信息
event = document.createEventObject();
This is to handle Internet Explorer. 这是为了处理Internet Explorer。 It generates an event object.
它生成一个事件对象。
event.eventType = "submit";
It will create an event of type "submit"
它将创建
"submit"
类型的事件
form.fireEvent("submit");
This will fire the event on form
这将在
form
上触发事件
Hope this will be helpful to you. 希望这对您有帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.