首页 > 代码库 > 兼容ie5-ie11及其他主流浏览器的js document.getElementsByClassName 方法

兼容ie5-ie11及其他主流浏览器的js document.getElementsByClassName 方法

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