因为选择转载还需要确认被转载人已同意,有点麻烦,所以选了原创,但是附上了原文地址
1. classList 在ie9中的不兼容
引入以下代码,即可
if (!("classList" in document.documentElement)) {
Object.defineProperty(HTMLElement.prototype, 'classList', {
get: function() {
var self = this;
function update(fn) {
return function(value) {
var classes = self.className.split(/\s+/g),
index = classes.indexOf(value);
fn(classes, index, value);
self.className = classes.join(" ");
}
}
return {
add: update(function(classes, index, value) {
if (!~index) classes.push(value);
}),
remove: update(function(classes, index) {
if (~index) classes.splice(index, 1);
}),
toggle: update(function(classes, index, value) {
if (~index)
classes.splice(index, 1);
else
classes.push(value);
}),
contains: function(value) {
return !!~self.className.split(/\s+/g).indexOf(value);
},
item: function(i) {
return self.className.split(/\s+/g)[i] || null;
}
};
}
});
}
https://blog.youkuaiyun.com/weixin_44860135/article/details/90404135 原文地址
2. postMessage 在ie9的不兼容问题
传参只支持字符串,ie10及以上支持对象和字符串。所以统一改为字符串
3. placeholder 在ie9的不兼容问题
/*
IE9placeholder支持
*/
if(!placeholderSupport()){ // 判断浏览器是否支持 placeholder
$('[placeholder]').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
if (input.val() == '' || input.val() == input.attr('placeholder')) {
input.addClass('placeholder');
input.val(input.attr('placeholder'));
}
}).blur();
};
function placeholderSupport() {
return 'placeholder' in document.createElement('input');
}