在IE6,7,8 中没有document.getElementsName() 此方法,因此兼容性写法为:
function getName(obj, cName) {
var obj = document || obj;
if (obj.getElementsByClassName) {
return obj.getElementsByClassName(cName);
}
else {
var arr = [];
var all = obj.getElementsByTagName('*');
for (var i = 0; i < all.length; i++) {
var allName = all[i].className.split(' ');
for (var j = 0; j < allName.length; j++) {
if (allName[j] == cName) {
arr.push(all[i]);
break;
}
}
}
return arr;
}
}