var getElementsByClassName = function(searchClass,node,tag) { if(document.getElementsByClassName){ return document.getElementsByClassName(searchClass) }else{ node = node || document; tag = tag || '*'; var returnElements = [] var els = (tag === "*" && node.all)? node.all : node.getElementsByTagName(tag); var i = els.length; searchClass = searchClass.replace(/-/g, "\-"); var pattern = new RegExp("(^|\s)"+searchClass+"(\s|$)"); while(--i >= 0){ if (pattern.test(els[i].className) ) { returnElements.push(els[i]); } } return returnElements; } } //调用方法 var shiToolBox=document.getElementsByClassName("aaa");
原分享地址:http://www.cnblogs.com/rubylouvre/archive/2009/07/24/1529640.html