给moz-firefox下添加IE方法和属性( 二 )


});
HTMLElement.prototype.__defineSetter__("outerHTML",function(sHTML){
varr=this.ownerDocument.createRange();
r.setStartBefore(this);
vardf=r.createContextualFragment(sHTML);
this.parentNode.replaceChild(df,this);
returnsHTML;
});
HTMLElement.prototype.__defineGetter__("outerHTML",function(){
varattr;
varattrs=this.attributes;
varstr="" this.tagName;
for(vari=0;iattrs.length;i){
attr=attrs[i];
if(attr.specified)
str ="" attr.name '="' attr.value '"';
}
if(!this.canHaveChildren)
returnstr "";
returnstr "" this.innerHTML "/" this.tagName "";
});
HTMLElement.prototype.__defineGetter__("canHaveChildren",function(){
switch(this.tagName.toLowerCase()){
case"area":
case"base":
case"basefont":
case"col":
case"frame":
case"hr":
case"img":
case"br":
case"input":
case"isindex":
case"link":
case"meta":
case"param":
returnfalse;
}
returntrue;
});

HTMLElement.prototype.__defineSetter__("innerText",function(sText){
varparsedText=document.createTextNode(sText);
this.innerHTML=parsedText;
returnparsedText;
});
HTMLElement.prototype.__defineGetter__("innerText",function(){
varr=this.ownerDocument.createRange();
r.selectNodeContents(this);
returnr.toString();
});
HTMLElement.prototype.__defineSetter__("outerText",function(sText){
varparsedText=document.createTextNode(sText);
this.outerHTML=parsedText;
returnparsedText;
});
HTMLElement.prototype.__defineGetter__("outerText",function(){
varr=this.ownerDocument.createRange();
r.selectNodeContents(this);
returnr.toString();
});
HTMLElement.prototype.attachEvent=function(sType,fHandler){
varshortTypeName=sType.replace(/on/,"");
fHandler._ieEmuEventHandler=function(e){
window.event=e;
returnfHandler();
}
this.addEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);
}
HTMLElement.prototype.detachEvent=function(sType,fHandler){
varshortTypeName=sType.replace(/on/,"");
if(typeof(fHandler._ieEmuEventHandler)=="function")
this.removeEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);
else
this.removeEventListener(shortTypeName,fHandler,true);
}
HTMLElement.prototype.contains=function(Node){//是否包含某节点
doif(Node==this)returntrue;
while(Node=Node.parentNode);
returnfalse;
}
HTMLElement.prototype.insertAdjacentElement=function(where,parsedNode){
switch(where){
case"beforeBegin":
this.parentNode.insertBefore(parsedNode,this);
break;
case"afterBegin":
this.insertBefore(parsedNode,this.firstChild);
break;
case"beforeEnd":
this.appendChild(parsedNode);
break;
case"afterEnd":
if(this.nextSibling)
this.parentNode.insertBefore(parsedNode,this.nextSibling);
else
this.parentNode.appendChild(parsedNode);
break;
}
}
HTMLElement.prototype.insertAdjacentHTML=function(where,htmlStr){
varr=this.ownerDocument.createRange();
r.setStartBefore(this);
varparsedHTML=r.createContextualFragment(htmlStr);
this.insertAdjacentElement(where,parsedHTML);
}
HTMLElement.prototype.insertAdjacentText=function(where,txtStr){
varparsedText=document.createTextNode(txtStr);
this.insertAdjacentElement(where,parsedText);
}
HTMLElement.prototype.attachEvent=function(sType,fHandler){
varshortTypeName=sType.replace(/on/,"");
fHandler._ieEmuEventHandler=function(e){
window.event=e;
returnfHandler();
}
this.addEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);
}
HTMLElement.prototype.detachEvent=function(sType,fHandler){
varshortTypeName=sType.replace(/on/,"");
if(typeof(fHandler._ieEmuEventHandler)=="function")
this.removeEventListener(shortTypeName,fHandler._ieEmuEventHandler,false);
else
this.removeEventListener(shortTypeName,fHandler,true);
}
}
//--
/script

推荐阅读