IE11上的whatinput.js问题

时间:2016-11-21 18:36:36

标签: javascript jquery internet-explorer internet-explorer-11

IE11在处理whatinput.js时出现以下错误:

"File: whatinput.js, Line: 38, Column: 9" Object doesn't support property or method 'hasAttribute'

Chrome运行就好了,我们尝试运行它的输入字段效果很好。

下面是脚本whatinput.js:

(function (a, b) {
    typeof define === "function" && define.amd ? define([], function () {
        return b()
    }) : typeof exports === "object" ? module.exports = b() : a.whatInput = b()
})(this, function () {
    function a(a) {
        clearTimeout(p);
        c(a);
        k = !0;
        p = setTimeout(function () {
            k = !1
        }, 1E3)
    }

    function b(a) {
        k || c(a)
    }

    function c(a) {
        var c = a.keyCode ? a.keyCode : a.which,
            b = a.target || a.srcElement,
            d = l[a.type];
        d === "pointer" && (d = typeof a.pointerType === "number" ? q[a.pointerType] : a.pointerType);
        if (h !== d && (i || !h || !(d === "keyboard" && o[c] !== "tab" && j.indexOf(b.nodeName.toLowerCase()) >=
            0))) h = d, f.setAttribute("data-whatinput", h), n.indexOf(h) === -1 && n.push(h);
        d === "keyboard" && g.indexOf(o[c]) === -1 && o[c] && g.push(o[c])
    }

    function d(a) {
        a = g.indexOf(o[a.keyCode ? a.keyCode : a.which]);
        a !== -1 && g.splice(a, 1)
    }
    var g = [],
        f = document.body,
        k = !1,
        h = null,
        j = ["input", "select", "textarea"],
        i = f.hasAttribute("data-whatinput-formtyping"),
        l = {
            keydown: "keyboard",
            mousedown: "mouse",
            mouseenter: "mouse",
            touchstart: "touch",
            pointerdown: "pointer",
            MSPointerDown: "pointer"
        },
        n = [],
        o = {
            9: "tab",
            13: "enter",
            16: "shift",
            27: "esc",
            32: "space",
            37: "left",
            38: "up",
            39: "right",
            40: "down"
        },
        q = {
            2: "touch",
            3: "touch",
            4: "mouse"
        },
        p;
    (function () {
        var c = "mousedown";
        window.PointerEvent ? c = "pointerdown" : window.MSPointerEvent && (c = "MSPointerDown");
        f.addEventListener ? (f.addEventListener(c, b), f.addEventListener("mouseenter", b), "ontouchstart" in document.documentElement && f.addEventListener("touchstart", a), f.addEventListener("keydown", b), f.addEventListener("keyup", d)) : (f.attachEvent(c, b), f.attachEvent("mouseenter", b), "ontouchstart" in document.documentElement && f.attachEvent("touchstart",
            a), f.attachEvent("keydown", b), f.attachEvent("keyup", d))
    })();
    return {
        ask: function () {
            return h
        },
        keys: function () {
            return g
        },
        types: function () {
            return n
        },
        set: c
    }
});

之前有没有人遇到过这个问题?如果是的话,采取了哪些措施来纠正。

0 个答案:

没有答案