IE 11 DispatchEvent [英] IE 11 DispatchEvent

查看:126
本文介绍了IE 11 DispatchEvent的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个datepicker(在JavaScript中),它有一个用于检查IE 8以及旧版和其他现代浏览器的部分。

We have a datepicker (in JavaScript) that has a section for checking IE 8 and older and other modern browsers.

if(-1 != navigator.userAgent.indexOf("MSIE")){
obj_caller.target.fireEvent("onchange");
}
else {
var evt = document.createEvent("HTMLEvents");
evt.initEvent("change", false, true);
obj_caller.target.dispatchEvent(evt);
}

它在Chrome,Firefox,IE8及以下版本中运行良好但在IE中失败11.我需要的是一种方法,让其他部分在IE 11中工作。我只是无法弄清楚什么是失败以及如何解决它。

It's working fine in Chrome, Firefox, IE8 and below but is failing in IE 11. What I need is a way to get the else part working in IE 11. I just cannot figure out what is failing and how to fix it.

谢谢。

推荐答案

您的问题是不应该在较新的IE版本中使用fireEvent。在IE9中添加了对dispatchEvent的支持。 http://help.dottoro.com/ljrinokx.php

Your problem is that fireEvent shouldn't be used in newer IE versions. Support for dispatchEvent was added in IE9. http://help.dottoro.com/ljrinokx.php

if(document.createEventObject) {
    obj_caller.target.fireEvent("onchange");
} else {
    var evt = document.createEvent("HTMLEvents");
    evt.initEvent("change", false, true);
    obj_caller.target.dispatchEvent(evt);
}

这篇关于IE 11 DispatchEvent的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆