function $class(classname, parentid){ var targets=[],kids=[]; if(parentid){ var parent=document.getElementById(parentid); kids=parent.getElementsByTagName("*"); }else{ kids=document.getElementsByTagName("*"); } for(var i=0;i<kids.length;i++){ if(kids[i].className.indexOf(classname)!=-1){ targets.push(kids[i]); } } return targets;//返回目标元素数组 }
时间: 2024-11-05 05:56:02