1、IE下时间格式识别NaN。
原因:IE无法识别yyyy-MM-dd格式,需要转换为yyyy/MM/dd。
//正则替换
replace(new RegExp(/-/gm) ,"/")
2、IE10- 无法声明let const
3、IE8不兼容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-不兼容JQ的ajax。
// 全局声明以下代码
jQuery.support.cors = true;
5、IE若需要兼容@media,需要将css写入到css文件中,写在style中无效
6、IE下background-size:cover无效
-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、事件监听全兼容
/**
* 添加事件监听 兼容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不支持数组的indexOf
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;
};
}