js兼容性处理

getElementsByClassName

if(!Element.prototype.hasOwnProperty("getElementsByClassName")){
    Element.prototype.getElementsByClassName = function(className,tag){
        tag = tag ? tag : "*";
        var elements = [],childNodes = this.getElementsByTagName(tag);
				
	   for(var i=0,length=childNodes.length;i<length;i++){
	      if(childNodes[i].className.length>0 && childNodes[i].className.indexOf(className)!=-1){
		    elements[elements.length] = childNodes[i];
		  }
	    }
	    return elements;
	}
}

猜你喜欢

转载自www.cnblogs.com/liwuming/p/10450752.html