【給moz-firefox下添加IE方法和屬性】在IECN看到心云寫的關(guān)于互換select的JS,因里面用到removeNode和swapNode等方法,導(dǎo)致在Firefox下無效 。剛剛Google了下,發(fā)現(xiàn)可以通過自定義原型來修正只在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){//設(shè)置或者檢索當(dāng)前事件句柄的層次冒泡
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(){//返回鼠標(biāo)移出的源節(jié)點(diǎn)
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(){//返回鼠標(biāo)移入的源節(jié)點(diǎn)
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){//替換指定節(jié)點(diǎn)
this.parentNode.replaceChild(Node,this);
}
Node.prototype.removeNode=function(removeChildren){//刪除指定節(jié)點(diǎn)
if(removeChildren)
returnthis.parentNode.removeChild(this);
else{
varrange=document.createRange();
range.selectNodeContents(this);
returnthis.parentNode.replaceChild(range.extractContents(),this);
}
}
Node.prototype.swapNode=function(Node){//交換節(jié)點(diǎn)
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);
推薦閱讀
- 怎么下載IE看過的視頻有哪些可行的方法
- 隔空喊話的下一句是
- 絕對(duì)定位的元素在ie6下不顯示隱藏了的有效解決方法
- 日月星辰皆是你下一句
- 玻尿酸豐下巴要多久消腫
- 彩禮一般提前多久給女方
- 不枉此生下一句是什么
- ie下沒有背景色bug的解決方法
- 交通銀行信用卡多長(zhǎng)時(shí)間下卡
- iqoo10pro價(jià)格
