最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

javascript firefox兼容ie的dom方法腳本

 更新時間:2008年05月18日 21:50:48   作者:  
js firefox下兼容ie的dom的實現(xiàn)方法小結(jié)。利用我們?yōu)榱思嫒荻酁g覽器寫出更好的效果代碼
if(!document.all){
//zzcv的ff ie兼容腳本
/*腳本沒有解決的問題及處理:

2.IE下,可以使用()或[]獲取集合類對象;Firefox下,只能使用[]獲取集合類對象. 
解決方法:統(tǒng)一使用[]獲取集合類對象. 
3.IE下,可以使用獲取常規(guī)屬性的方法來獲取自定義屬性,也可以使用getAttribute()獲取自定義屬性;Firefox下,只能使用getAttribute()獲取自定義屬性. 
解決方法:統(tǒng)一通過getAttribute()獲取自定義屬性. 
4.IE下,HTML對象的ID可以作為document的下屬對象變量名直接使用;Firefox下則不能.
5.Firefox下,可以使用與HTML對象ID相同的變量名;IE下則不能。
解決方法:使用document.getElementById("idName")代替document.idName.最好不要取HTML對象ID相同的變量名,以減少錯誤;在聲明變量時,一律加上var,以避免歧義. 
6.IE下input.type屬性為只讀;但是Firefox下input.type屬性為讀寫. 
8.IE下,可以通過showModalDialog和showModelessDialog打開模態(tài)和非模態(tài)窗口;Firefox下則不能
9.Firefox的body在body標簽沒有被瀏覽器完全讀入之前就存在;而IE的body則必須在body標簽被瀏覽器完全讀入之后才存在
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é)點操作兼容
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;});

}

相關(guān)文章

  • iframe的基本介紹與使用

    iframe的基本介紹與使用

    本文將給大家詳細介紹一下iframe的基本介紹與使用,iframe(內(nèi)嵌框架)是 HTML 中一種用于將一個網(wǎng)頁嵌入到另一個網(wǎng)頁中的標簽,它可以在一個頁面中顯示來自其他頁面的內(nèi)容,需要的朋友可以參考下
    2024-02-02
  • JS如何實現(xiàn)form表單登錄驗證并使用MD5加密詳解

    JS如何實現(xiàn)form表單登錄驗證并使用MD5加密詳解

    表單驗證為終端用戶檢測無效的數(shù)據(jù)并標記這些錯誤,是一種用戶體驗的優(yōu)化,下面這篇文章主要給大家介紹了關(guān)于JS如何實現(xiàn)form表單登錄驗證并使用MD5加密的相關(guān)資料,需要的朋友可以參考下
    2023-06-06
  • 一個JavaScript函數(shù)把URL參數(shù)解析成Json對象

    一個JavaScript函數(shù)把URL參數(shù)解析成Json對象

    一個JavaScript函數(shù)parseQueryString,它的用途是把URL參數(shù)解析為一個對象,很實用,大家可以看看
    2014-09-09
  • 微信小程序?qū)崿F(xiàn)商城倒計時

    微信小程序?qū)崿F(xiàn)商城倒計時

    這篇文章主要為大家詳細介紹了微信小程序?qū)崿F(xiàn)商城倒計時,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2019-06-06
  • 小程序開發(fā)實現(xiàn)access_token統(tǒng)一管理

    小程序開發(fā)實現(xiàn)access_token統(tǒng)一管理

    本文主要介紹了小程序開發(fā)實現(xiàn)access_token統(tǒng)一管理,文中通過示例代碼介紹的非常詳細,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-07-07
  • JavaScript獲取數(shù)組最后一個元素的3種方法以及性能

    JavaScript獲取數(shù)組最后一個元素的3種方法以及性能

    在開發(fā)過程中,我們常常需要得到j(luò)s數(shù)組的最后一個數(shù)組元素,下面這篇文章主要給大家介紹了關(guān)于JavaScript獲取數(shù)組最后一個元素的3種方法以及性能,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下
    2023-06-06
  • 原生js模擬淘寶購物車項目實戰(zhàn)

    原生js模擬淘寶購物車項目實戰(zhàn)

    這篇文章主要向大家推薦了一個原生js模擬淘寶購物車項目實戰(zhàn),包括商品的單選、全選、刪除、修改數(shù)量、價格計算、數(shù)目計算、預(yù)覽等功能的實現(xiàn),感興趣的小伙伴們可以參考一下
    2015-11-11
  • 一文看懂如何簡單實現(xiàn)節(jié)流函數(shù)和防抖函數(shù)

    一文看懂如何簡單實現(xiàn)節(jié)流函數(shù)和防抖函數(shù)

    這篇文章主要給大家介紹了如何通過一文看懂簡單實現(xiàn)節(jié)流函數(shù)和防抖函數(shù)的相關(guān)資料,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09
  • yii form 表單提交之前JS在提交按鈕的驗證方法

    yii form 表單提交之前JS在提交按鈕的驗證方法

    很多時候,需要對Yii表單model中的對象設(shè)置的rules進行判斷,但是有的時候可能需要在提交之前就在客戶端進行驗證。怎么處理呢?接下來通過本文給大家分享yii form 表單提交之前JS在提交按鈕的驗證方法,需要的的朋友參考下
    2017-03-03
  • 分享純手寫漂亮的表單驗證

    分享純手寫漂亮的表單驗證

    最近沒有項目做,閑來沒事,于是自己動手寫了幾個表單驗證,特此分享供大家參考
    2015-11-11

最新評論

习水县| 龙门县| 农安县| 陇川县| 车致| 杨浦区| 安图县| 沂源县| 平凉市| 义乌市| 临夏县| 陈巴尔虎旗| 文安县| 胶州市| 青岛市| 防城港市| 从江县| 上思县| 桐庐县| 茂名市| 招远市| 长宁县| 静乐县| 冷水江市| 鄂温| 二连浩特市| 连云港市| 革吉县| 锡林郭勒盟| 江安县| 阜宁县| 闽清县| 巴林右旗| 锡林浩特市| 林州市| 灵丘县| 台前县| 鄂伦春自治旗| 象州县| 松江区| 沙坪坝区|