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

在IECN看到心云写的关于互换select的JS,因里面用到removeNode和swapNode等方法,导致在Firefox下无效。刚刚Google了下,发现可以通过自定义原型来修正只在IE下有效的属性与方法。 
原文参考:http://www.phpx.com/happy/top97619.html 
修改方案如下: 
scriptlanguage="javascript"type="text/javascript" 
!-- 
if(window.Event){//修正Event的DOM 
/* 
IE5MacIE5MozillaKonqueror2.2Opera5 
eventyesyesyesyesyes 
event.returnValueyesyesnonono 
event.cancelBubbleyesyesnonono 
event.srcElementyesyesnonono 
event.fromElementyesyesnonono 
*/ 
Event.prototype.__defineSetter__("returnValue",function(b){// 
if(!b)this.preventDefault(); 
returnb; 
}); 
Event.prototype.__defineSetter__("cancelBubble",function(b){//设置或者检索当前事件句柄的层次冒泡 
if(b)this.stopPropagation(); 
returnb; 
}); 
Event.prototype.__defineGetter__("srcElement",function(){ 
varnode=this.target; 
while(node.nodeType!=1)node=node.parentNode; 
returnnode; 
}); 
Event.prototype.__defineGetter__("fromElement",function(){//返回鼠标移出的源节点 
varnode; 
if(this.type=="mouseover") 
node=this.relatedTarget; 
elseif(this.type=="mouseout") 
node=this.target; 
if(!node)return; 
while(node.nodeType!=1)node=node.parentNode; 
returnnode; 
}); 
Event.prototype.__defineGetter__("toElement",function(){//返回鼠标移入的源节点 
varnode; 
if(this.type=="mouseout") 
node=this.relatedTarget; 
elseif(this.type=="mouseover") 
node=this.target; 
if(!node)return; 
while(node.nodeType!=1)node=node.parentNode; 
returnnode; 
}); 
Event.prototype.__defineGetter__("offsetX",function(){ 
returnthis.layerX; 
}); 
Event.prototype.__defineGetter__("offsetY",function(){ 
returnthis.layerY; 
}); 
} 
if(window.Document){//修正Document的DOM 
/* 
IE5MacIE5MozillaKonqueror2.2Opera5 
document.documentElementyesyesyesyesno 
document.activeElementyesnullnonono 
*/ 
} 
if(window.Node){//修正Node的DOM 
/* 
IE5MacIE5MozillaKonqueror2.2Opera5 
Node.containsyesyesnonoyes 
Node.replaceNodeyesnononono 
Node.removeNodeyesnononono 
Node.childrenyesyesnonono 
Node.hasChildNodesyesyesyesyesno 
Node.childNodesyesyesyesyesno 
Node.swapNodeyesnononono 
Node.currentStyleyesyesnonono 
*/ 
Node.prototype.replaceNode=function(Node){//替换指定节点 
this.parentNode.replaceChild(Node,this); 
} 
Node.prototype.removeNode=function(removeChildren){//删除指定节点 
if(removeChildren) 
returnthis.parentNode.removeChild(this); 
else{ 
varrange=document.createRange(); 
range.selectNodeContents(this); 
returnthis.parentNode.replaceChild(range.extractContents(),this); 
} 
} 
Node.prototype.swapNode=function(Node){//交换节点 
varnextSibling=this.nextSibling; 
varparentNode=this.parentNode; 
node.parentNode.replaceChild(this,Node); 
parentNode.insertBefore(node,nextSibling); 
} 
} 
if(window.HTMLElement){ 
HTMLElement.prototype.__defineGetter__("all",function(){ 
vara=this.getElementsByTagName("*"); 
varnode=this; 
a.tags=function(sTagName){ 
returnnode.getElementsByTagName(sTagName); 
} 
returna; 
}); 
HTMLElement.prototype.__defineGetter__("parentElement",function(){ 
if(this.parentNode==this.ownerDocument)returnnull; 
returnthis.parentNode; 
}); 
HTMLElement.prototype.__defineGetter__("children",function(){ 
vartmp=[]; 
varj=0; 
varn; 
for(vari=0;ithis.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; 
} 
} 
returntmp; 
}); 
HTMLElement.prototype.__defineGetter__("currentStyle",function(){ 
returnthis.ownerDocument.defaultView.getComputedStyle(this,null); 
}); 
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 
相关内容
电视机怎样开启投屏|手机投屏到老电视的方法
电视机怎样开启投屏|手机投屏到老电视的方法,投屏,方法,开启,...
u盘文件删除如何恢复|u盘免费文件恢复的3个方法
u盘文件删除如何恢复|u盘免费文件恢复的3个方法,文件恢复,方...
电脑出现蓝屏怎么办|电脑经常蓝屏的修复方法
电脑出现蓝屏怎么办|电脑经常蓝屏的修复方法,蓝屏,方法,修复,...
uc浏览器无痕浏览在哪里设置|手机浏览器开启无
uc浏览器无痕浏览在哪里设置|手机浏览器开启无痕模式的方法,...
手机贴膜怎么贴教程|成功率极高的手机贴膜方法
手机贴膜怎么贴教程|成功率极高的手机贴膜方法,方法,教程,屏...
ps怎么载入选区|ps载入选区的详细操作方法
ps怎么载入选区|ps载入选区的详细操作方法,操作方法,执行,设...
微信小视频怎么下载保存|微信保存小视频和聊天
微信小视频怎么下载保存|微信保存小视频和聊天记录的方法,小...
手写文字转换成电子版的手方法|怎么样拍照手写
手写文字转换成电子版的手方法|怎么样拍照手写笔记变成电子...
为什么安装不了软件|windows10系统不能装软件解
为什么安装不了软件|windows10系统不能装软件解决方法,装软件...
ivo手机卡顿反应慢怎么办|vivo手机卡顿最正确解
ivo手机卡顿反应慢怎么办|vivo手机卡顿最正确解决方法,卡顿,...
买笔记本电脑要注意什么|选购笔记本电脑的最佳
买笔记本电脑要注意什么|选购笔记本电脑的最佳方法,固态硬盘,...
网站进不去是怎么回事|网络正常网站开不了的解
网站进不去是怎么回事|网络正常网站开不了的解决方法,网站,网...
netcore路由器怎么设置|磊科nw无线路由器设置方
netcore路由器怎么设置|磊科nw无线路由器设置方法图解,设置,...
excel怎么筛选出自己想要的数据|excel快速筛选
excel怎么筛选出自己想要的数据|excel快速筛选数据的操作方...
win11右键怎么设置原来的模样|Windows11右键太
win11右键怎么设置原来的模样|Windows11右键太宽解决方法,右...