MouseEvent无法在Internet Explorer中运行 [英] MouseEvent not working in Internet Explorer

查看:2842
本文介绍了MouseEvent无法在Internet Explorer中运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是我吗?这是我的IE吗?或者为什么这段代码不适用于IE 11:

Is it me? Is it my IE? or why is this code not working on IE 11:

var clicker = new MouseEvent("click", {
  'bubbles': true,
  'cancelable': true,
  'view': window,
  'detail': 0,
  'screenX': 0,
  'screenY': 0,
  'clientX': 0,
  'clientY': 0,
  'ctrlKey': false,
  'altKey': false,
  'shiftKey': false,
  'metaKey': false,
  'button': 0,
  'relatedTarget': null
});

我在控制台上获得对象不支持此操作(F12)。我不得不想出一个解决方法,但我只是不明白为什么以前的代码不起作用(顺便说一下,前面的代码来自这里: https://msdn.microsoft.com/en-us/library/ie/dn905219(v = vs.85 ).aspx (创建和触发合成事件)。
解决方法:

I get "Object doesn't support this action" on the console (F12). I had to come up with a workaround, but I just don't get why is the previous code not working (by the way, the previous code comes from here: https://msdn.microsoft.com/en-us/library/ie/dn905219(v=vs.85).aspx (Creating and firing synthetic events). Workaround:

if (typeof MouseEvent !== 'function') {
    (function (){
        var _MouseEvent = window.MouseEvent;
        window.MouseEvent = function (type, dict){
            dict = dict | {};
            var event = document.createEvent('MouseEvents');
            event.initMouseEvent(
                    type,
                    (typeof dict.bubbles == 'undefined') ? true : !!dict.bubbles,
                    (typeof dict.cancelable == 'undefined') ? false : !!dict.cancelable,
                    dict.view || window,
                    dict.detail | 0,
                    dict.screenX | 0,
                    dict.screenY | 0,
                    dict.clientX | 0,
                    dict.clientY | 0,
                    !!dict.ctrlKey,
                    !!dict.altKey,
                    !!dict.shiftKey,
                    !!dict.metaKey,
                    dict.button | 0,
                    dict.relatedTarget || null
            );
            return event;
        }
    })();
}

这笔交易是我想将已弃用的createEvent / initXXXXEvent迁移到新的form(var event = new XXXXEvent(...))尽可能不依赖于弃用的方法。

The deal is that I want to migrate the deprecated createEvent/initXXXXEvent to the new form (var event = new XXXXEvent(...) ) whenever possible and not rely on the deprecated methods.

推荐答案

MSDN来自您提供的链接的文档表明DOM L4事件构造函数模式的新语法:

The MSDN documentation from the link you provided indicates that the new syntax for the DOM L4 event constructor pattern:


适用于Windows 10技术预览版的Internet Explorer和
之后。

Applies to Internet Explorer for Windows 10 Technical Preview and later.

这是与您使用的IE不同的版本。所以预计IE11不支持此功能

which is a different version of IE from what you are using. So it's expected that IE11 does not support this feature

这篇关于MouseEvent无法在Internet Explorer中运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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