标签:io ar for sp on cti as js return
function getElementsByClassName( parent,tag,className ){
var aEls = parent.getElementsByTagName(tag);
var arr = [];
for (var i = 0; i < aEls.length; i++) {
var aClassName = aEls[i].className.split(‘ ‘);
for (var j = 0; j < aClassName.length; j++) {
if(aClassName[j] == className){
arr.push(aEls[i]);
//如果className里面包含‘box‘ 则跳出循环
break; //防止一个元素出现多次相同的class被添加多次
}
};
};
return arr;
}
js通过class获取元素getElementsByClassName函数封装
标签:io ar for sp on cti as js return
原文地址:http://www.cnblogs.com/lw9413/p/4064086.html