IE compatibility issues (continuously supplemented)

1. The time format under IE recognizes NaN.

Reason: IE cannot recognize the yyyy-MM-dd format and needs to be converted to yyyy/MM/dd.

//正则替换
replace(new RegExp(/-/gm) ,"/")

2. IE10- cannot declare let const

3. IE8 is not compatible with filter

if (!Array.prototype.filter)
{
    Array.prototype.filter = function(fun /*, thisp */)
    {
        "use strict";

        if (this === void 0 || this === null)
            throw new TypeError();

        var t = Object(this);
        var len = t.length >>> 0;
        if (typeof fun !== "function")
            throw new TypeError();

        var res = [];
        var thisp = arguments[1];
        for (var i = 0; i < len; i++)
        {
            if (i in t)
            {
                var val = t[i]; // in case fun mutates this
                if (fun.call(thisp, val, i, t))
                    res.push(val);
            }
        }

        return res;
    };
}

4. IE10-incompatible with JQ's ajax.

// 全局声明以下代码
jQuery.support.cors = true;

5. If IE needs to be compatible with @media, it needs to write the css into the css file, and writing it in the style is invalid

6. Background-size: cover is invalid under IE

-ms-filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='dist/images/registerBg.png',sizingMethod=scale); 
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='dist/images/registerBg.png',sizingMethod=scale);

7. Event monitoring is fully compatible

/**
 * 添加事件监听 兼容IE8
 * @param el
 * @param type
 * @param fn
 */
function addListener(el, type, fn) {
    if (el.addEventListener) {
        el.addEventListener(type, fn, false);
    } else if (el.attachEvent) {
        el.attachEvent('on' + type, fn);
    }
}

/**
 * 移除事件监听 兼容IE8
 * @param el
 * @param type
 * @param fn
 */
function removeListener(el, type, fn) {
    if (el.removeEventListener) {
        el.removeEventListener(type, fn, false);
    } else if (el.detachEvent) {
        el.detachEvent('on' + type, fn);
    }
}

8. IE8 does not support indexOf of arrays

if (!Array.prototype.indexOf){
    Array.prototype.indexOf = function(elt /*, from*/){
        var len = this.length >>> 0;

        var from = Number(arguments[1]) || 0;
        from = (from < 0)
            ? Math.ceil(from)
            : Math.floor(from);
        if (from < 0)
            from += len;

        for (; from < len; from++){
            if (from in this && this[from] === elt)
                return from;
        }
        return -1;
    };
}

 

Guess you like

Origin blog.csdn.net/QiZi_Zpl/article/details/105763690