javascript firefox兼容ie的dom方法腳本
//zzcv的ff ie兼容腳本
/*腳本沒(méi)有解決的問(wèn)題及處理:
2.IE下,可以使用()或[]獲取集合類對(duì)象;Firefox下,只能使用[]獲取集合類對(duì)象.
解決方法:統(tǒng)一使用[]獲取集合類對(duì)象.
3.IE下,可以使用獲取常規(guī)屬性的方法來(lái)獲取自定義屬性,也可以使用getAttribute()獲取自定義屬性;Firefox下,只能使用getAttribute()獲取自定義屬性.
解決方法:統(tǒng)一通過(guò)getAttribute()獲取自定義屬性.
4.IE下,HTML對(duì)象的ID可以作為document的下屬對(duì)象變量名直接使用;Firefox下則不能.
5.Firefox下,可以使用與HTML對(duì)象ID相同的變量名;IE下則不能。
解決方法:使用document.getElementById("idName")代替document.idName.最好不要取HTML對(duì)象ID相同的變量名,以減少錯(cuò)誤;在聲明變量時(shí),一律加上var,以避免歧義.
6.IE下input.type屬性為只讀;但是Firefox下input.type屬性為讀寫(xiě).
8.IE下,可以通過(guò)showModalDialog和showModelessDialog打開(kāi)模態(tài)和非模態(tài)窗口;Firefox下則不能
9.Firefox的body在body標(biāo)簽沒(méi)有被瀏覽器完全讀入之前就存在;而IE的body則必須在body標(biāo)簽被瀏覽器完全讀入之后才存在
10.
*/
//文檔兼容
HTMLDocument.prototype.__defineGetter__("all",function(){
return this.getElementsByName("*");});
HTMLFormElement.constructor.prototype.item=function(s){
return this.elements[s];};
HTMLCollection.prototype.item=function(s){
return this[s];};
//事件兼容
window.constructor.prototype.__defineGetter__("event",function(){
for(var o=arguments.callee.caller,e=null;o!=null;o=o.caller){
e=o.arguments[0];
if(e&&(e instanceof Event))
return e;}
return null;});
window.constructor.prototype.attachEvent=HTMLDocument.prototype.attachEvent=HTMLElement.prototype.attachEvent=function(e,f){
this.addEventListener(e.replace(/^on/i,""),f,false);};
window.constructor.prototype.detachEvent=HTMLDocument.prototype.detachEvent=HTMLElement.prototype.detachEvent=function(e,f){
this.removeEventListener(e.replace(/^on/i,""),f,false);};
with(window.Event.constructor.prototype){
__defineGetter__("srcElement",function(){
return this.target;});
__defineSetter__("returnValue",function(b){
if(!b)this.preventDefault();});
__defineSetter__("cancelBubble",function(b){
if(b)this.stopPropagation();});
__defineGetter__("fromElement",function(){
var o=(this.type=="mouseover"&&this.relatedTarget)||(this.type=="mouseout"&&this.target)||null;
if(o)
while(o.nodeType!=1)
o=o.parentNode;
return o;});
__defineGetter__("toElement",function(){
var o=(this.type=="mouseover"&&this.target)||(this.type=="mouseout"&&this.relatedTarget)||null;
if(o)
while(o.nodeType!=1)
o=o.parentNode;
return o;});
__defineGetter__("x",function(){
return this.pageX;});
__defineGetter__("y",function(){
return this.pageY;});
__defineGetter__("offsetX",function(){
return this.layerX;});
__defineGetter__("offsetY",function(){
return this.layerY;});
}
//節(jié)點(diǎn)操作兼容
with(window.Node.prototype){
replaceNode=function(o){
this.parentNode.replaceChild(o,this);}
removeNode=function(b){
if(b)
return this.parentNode.removeChild(this);
var range=document.createRange();
range.selectNodeContents(this);
return this.parentNode.replaceChild(range.extractContents(),this);}
swapNode=function(o){
return this.parentNode.replaceChild(o.parentNode.replaceChild(this,o),this);}
contains=function(o){
return o?((o==this)?true:arguments.callee(o.parentNode)):false;}
}
//HTML元素兼容
with(window.HTMLElement.prototype){
__defineGetter__("parentElement",function(){
return (this.parentNode==this.ownerDocument)?null:this.parentNode;});
__defineGetter__("children",function(){
var c=[];
for(var i=0,cs=this.childNodes;i<cs.length;i++){
if(cs[i].nodeType==1)
c.push(cs[i]);}
return c;});
__defineGetter__("canHaveChildren",function(){
return !/^(area|base|basefont|col|frame|hr|img|br|input|isindex|link|meta|param)$/i.test(this.tagName);});
__defineSetter__("outerHTML",function(s){
var r=this.ownerDocument.createRange();
r.setStartBefore(this);
void this.parentNode.replaceChild(r.createContextualFragment(s),this);
return s;});
__defineGetter__("outerHTML",function(){
var as=this.attributes;
var str="<"+this.tagName;
for(var i=0,al=as.length;i<al;i++){
if(as[i].specified)
str+=" "+as[i].name+"=""+as[i].value+""";}
return this.canHaveChildren?str+">":str+">"+this.innerHTML+"</"+this.tagName+">";});
__defineSetter__("innerText",function(s){
return this.innerHTML=document.createTextNode(s);});
__defineGetter__("innerText",function(){
var r=this.ownerDocument.createRange();
r.selectNodeContents(this);
return r.toString();});
__defineSetter__("outerText",function(s){
void this.parentNode.replaceChild(document.createTextNode(s),this);
return s});
__defineGetter__("outerText",function(){
var r=this.ownerDocument.createRange();
r.selectNodeContents(this);
return r.toString();});
insertAdjacentElement=function(s,o){
return (s=="beforeBegin"&&this.parentNode.insertBefore(o,this))||(s=="afterBegin"&&this.insertBefore(o,this.firstChild))||(s=="beforeEnd"&&this.appendChild(o))||(s=="afterEnd"&&((this.nextSibling)&&this.parentNode.insertBefore(o,this.nextSibling)||this.parentNode.appendChild(o)))||null;}
insertAdjacentHTML=function(s,h){
var r=this.ownerDocument.createRange();
r.setStartBefore(this);
this.insertAdjacentElement(s,r.createContextualFragment(h));}
insertAdjacentText=function(s,t){
this.insertAdjacentElement(s,document.createTextNode(t));}
}
//XMLDOM兼容
window.ActiveXObject=function(s){
switch(s){
case "XMLDom":
document.implementation.createDocument.call(this,"text/xml","", null);
//domDoc = document.implementation.createDocument("text/xml","", null);
break;
}
}
XMLDocument.prototype.LoadXML=function(s){
for(var i=0,cs=this.childNodes,cl=childNodes.length;i<cl;i++)
this.removeChild(cs[i]);
this.appendChild(this.importNode((new DOMParser()).parseFromString(s,"text/xml").documentElement,true));}
XMLDocument.prototype.selectSingleNode=Element.prototype.selectSingleNode=function(s){
return this.selectNodes(s)[0];}
XMLDocument.prototype.selectNodes=Element.prototype.selectNodes=function(s){
var rt=[];
for(var i=0,rs=this.evaluate(s,this,this.createNSResolver(this.ownerDocument==null?this.documentElement:this.ownerDocument.documentElement),XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,null),sl=rs.snapshotLength;i<sl;i++)
rt.push(rs.snapshotItem(i));
return rt;}
XMLDocument.prototype.__proto__.__defineGetter__("xml",function(){
try{
return new XMLSerializer().serializeToString(this);}
catch(e){
return document.createElement("div").appendChild(this.cloneNode(true)).innerHTML;}});
Element.prototype.__proto__.__defineGetter__("xml",function(){
try{
return new XMLSerializer().serializeToString(this);}
catch(e){
return document.createElement("div").appendChild(this.cloneNode(true)).innerHTML;}});
XMLDocument.prototype.__proto__.__defineGetter__("text",function(){
return this.firstChild.textContent;});
Element.prototype.__proto__.__defineGetter__("text",function(){
return this.textContent;});
Element.prototype.__proto__.__defineSetter__("text",function(s){
return this.textContent=s;});
}
- javascript 獲取HTML DOM父、子、臨近節(jié)點(diǎn)
- JavaScript 節(jié)點(diǎn)操作 以及DOMDocument屬性和方法
- javascript獲取dom的下一個(gè)節(jié)點(diǎn)方法
- JavaScript獲取DOM元素的11種方法總結(jié)
- JavaScript DOM節(jié)點(diǎn)操作方法總結(jié)
- javascript dom操作之cloneNode文本節(jié)點(diǎn)克隆使用技巧
- JavaScript與DOM組合動(dòng)態(tài)創(chuàng)建表格實(shí)例
- JavaScript實(shí)現(xiàn)獲取dom中class的方法
- JavaScript中對(duì)DOM節(jié)點(diǎn)的訪問(wèn)、創(chuàng)建、修改、刪除
- javascript DOM 操作基礎(chǔ)知識(shí)小結(jié)
- 淺談Javascript中的12種DOM節(jié)點(diǎn)類型
- js中script的上下放置區(qū)別,Dom的增刪改創(chuàng)建操作實(shí)例分析
相關(guān)文章
JavaScript實(shí)現(xiàn)動(dòng)畫(huà)打開(kāi)半透明提示層的方法
這篇文章主要介紹了JavaScript實(shí)現(xiàn)動(dòng)畫(huà)打開(kāi)半透明提示層的方法,涉及javascript操作DOM的相關(guān)技巧,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2015-04-04JavaScript模擬實(shí)現(xiàn)自由落體效果
這篇文章主要為大家詳細(xì)介紹了JavaScript模擬實(shí)現(xiàn)自由落體效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-08-08JS密碼生成與強(qiáng)度檢測(cè)完整實(shí)例(附demo源碼下載)
這篇文章主要介紹了JS密碼生成與強(qiáng)度檢測(cè)完整實(shí)例,涉及JavaScript密碼的生成,破解時(shí)間計(jì)算,密碼安全監(jiān)測(cè)及大小寫(xiě)鎖定判斷等功能的實(shí)現(xiàn)技巧,并附帶demo源碼供讀者下載參考,需要的朋友可以參考下2016-04-04js微信應(yīng)用場(chǎng)景之微信音樂(lè)相冊(cè)案例分享
這篇文章主要為大家分享了js微信應(yīng)用場(chǎng)景之微信音樂(lè)相冊(cè)案例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08JS與SQL方式隨機(jī)生成高強(qiáng)度密碼示例
這篇文章主要介紹了JS與SQL方式隨機(jī)生成高強(qiáng)度密碼,結(jié)合實(shí)例形式分析了javascript方式與SQL方式生成高強(qiáng)度密碼的相關(guān)操作技巧,需要的朋友可以參考下2018-12-12js 動(dòng)態(tài)創(chuàng)建 html元素
最近在學(xué)習(xí)js 寫(xiě)了個(gè)簡(jiǎn)單的效果,菜鳥(niǎo)可以學(xué)習(xí)學(xué)習(xí),基本原理:使用隨即數(shù)設(shè)置top 和left的值,2009-07-07關(guān)于事件mouseover ,mouseout ,mouseenter,mouseleave的區(qū)別
mouseover ,mouseout ,mouseenter,mouseleave,都是鼠標(biāo)點(diǎn)擊而觸發(fā)的事件,各自代表什么意思,有哪些區(qū)別呢?下面跟著腳本之家小編一起看看吧2015-10-10JS使用oumousemove和oumouseout動(dòng)態(tài)改變圖片顯示的方法
這篇文章主要介紹了JS使用oumousemove和oumouseout動(dòng)態(tài)改變圖片顯示的方法,涉及javascript鼠標(biāo)事件及圖片操作技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-03-03