首页 > 代码库 > 监听浏览器使用不同版本js并且处理ie兼容getElementByClassName

监听浏览器使用不同版本js并且处理ie兼容getElementByClassName

if(window.addEventListener){
document.write(‘<script src="http://www.mamicode.com/js/jquery-2.1.4.min.js"><\/script>‘);

}else if(window.attachEvent){
document.write(‘<script src="http://www.mamicode.com/js/jquery-1.8.3.min.js"><\/script>‘);
//解决ie兼容getElementByClassName
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;
};
}
//


}else{
document.write(‘<script src="http://www.mamicode.com/js/jquery-2.1.4.min.js"><\/script>‘);
}

监听浏览器使用不同版本js并且处理ie兼容getElementByClassName