function getByClass(cName) {
if (document.getElementsByClassName)
return document.getElementsByClassName(cName);
else {
var arr = [];
var allElements = document.getElementsByTagName('*');
for (var i = 0; i < allElements.length; i++) {
var allCNames = allElements[i].className.split(' ');
for (var j = 0; j < allCNames.length; j++) {
if (allCNames[j] == cName) {
arr.push(allElements[i]);
break;
}
}
}
return arr;
}
}
浅谈兼容IE6/7的getElementsByClassName的实现
本文转载:CSDN博客