输入:className:类名;root:父节点,在此节点下查找,string/node; tagName:找某一类标签
function getElementsByClassName(className,root,tagName){
if(root){
root=typeof root=="string"?document.getElementById(root):root;
}else{
root=document.body;
}
tagName=tagName||"*";
var els=root.getElementsByTagName(tagName),arr=[];
for(var i=0;i<els.length;i++){
var classArray=els[i].className.split(" ");
for(var j=0;j<classArray.length;j++){
if(classArray[j]==className){
arr.push(els[i]);
break;
}
}
}
return arr;
}