统一接口:为FireFox添加IE的方法和属性的js代码

2019-06-03 00:22:36于海丽

      return node.getElementsByTagName(sTagName); 
      } 
    return a; 
    }); 
  HTMLElement.prototype.__defineGetter__("parentElement",function(){ 
    if(this.parentNode==this.ownerDocument)return null; 
    return this.parentNode; 
    }); 
  HTMLElement.prototype.__defineGetter__("children",function(){ 
    var tmp=[]; 
    var j=0; 
    var n; 
    for(var i=0;i<this.childNodes.length;i++){ 
      n=this.childNodes[i]; 
      if(n.nodeType==1){ 
        tmp[j++]=n; 
        if(n.name){ 
          if(!tmp[n.name]) 
            tmp[n.name]=[]; 
          tmp[n.name][tmp[n.name].length]=n; 
          } 
        if(n.id) 
          tmp[n.id]=n; 
        } 
      } 
    return tmp; 
    }); 
  HTMLElement.prototype.__defineGetter__("currentStyle", function(){ 
    return this.ownerDocument.defaultView.getComputedStyle(this,null); 
    }); 
  HTMLElement.prototype.__defineSetter__("outerHTML",function(sHTML){ 
    var r=this.ownerDocument.createRange(); 
    r.setStartBefore(this); 
    var df=r.createContextualFragment(sHTML); 
    this.parentNode.replaceChild(df,this); 
    return sHTML; 
    }); 
  HTMLElement.prototype.__defineGetter__("outerHTML",function(){ 
    var attr; 
    var attrs=this.attributes; 
    var str="<"+this.tagName; 
    for(var i=0;i<attrs.length;i++){ 
      attr=attrs[i]; 
      if(attr.specified) 
        str+=" "+attr.name+'="'+attr.value+'"';