getByclass传入两个参数,oParent是父集,sClass是要传入class名称
1 function getByClass(oParent,sClass){ 2 var aChild = oParent.getElementsByTagName("*"), 3 result = []; 4 for(var i =0;i<aChild.length;i++){ 5 if(aChild[i].className.match(new RegExp("(\s|^)" + sClass+ "(\s|$)"))){ //判断是否有该class 6 result.push(aChild[i]); 7 }; 8 }; 9 return result; 10 };