1、IE8以下不支持getElementsByClassName方法
//解决IE8之类不支持getElementsByClassName
if (!document.getElementsByClassName) {
document.getElementsByClassName = function (className, element) {
var children = (element || document).getElementsByTagName('*');
var elements = new Array();
for (var i = 0; i < children.length; i++) {
var child = children[i];
var classNames = child.className.split(' ');
for (var j = 0; j < classNames.length; j++) {
if (classNames[j] == className) {
elements.push(child);
break;
}
}
}
return elements;
};
}
2、IE8不支持数组的indexOf方法 如何解决
//添加数组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;
};
}
3、nth-child
ul li:nth-child(1){
color:#fff;
}/*选取第一个li*/
ul li:nth-child(odd){
color:#fff;
}/*选取偶数*/
ul li:nth-child(even){
color:#fff;
}/*选取奇数*/
ul li:nth-child(3n+1){
color:#fff;
}/*选取3n+1个元素*/
ie8不兼容nth-child()
ul li:first-child{
color:#fff;
}/*选取第一个li*/
ul li:first-child+li+li{
color:#fff;
}/*选取第三个li*/
4、ie8不兼容opacity
filter: progid:DXImageTransform.Microsoft.Alpha(opacity=70);