javascript開發紀要,瀏覽器差異

來源:互聯網
上載者:User

1.ff和ie判斷DOM對象是否載入完成

ie中的dom對象有readyState屬性,可以通過readyState=="complete"來判斷。
ff中dom對象沒有readyState屬性,只能使用onload事件。dom.onload = function(){}

2.ff和ie使用innerHTML 屬性給對象填充內容

ff一切正常
ie重複給某對象付值,dom.innerHTML ="<input id='input'></input>" 擷取input對象的value始終不變。
解決辦法每次付值前清空  dom.innerHTML ="";dom.innerHTML ="<input id='input'></input>"

3.js檔案中使用document.write("<script type='text/javascript' src=''/>")輸出script標籤

ff使用以上語句指令碼可以正確引入並執行。
ie可以輸出標本但無法執行,需使用結束標籤document.write("<script type='text/javascript' src=''></script>")

4.<script type='text/javascript'></script>中使用document.write("<script type='text/javascript' src=''></script>")輸出script執行

ff ie都報錯,由標籤符號< >導致。
解決方案一:
<script type='text/javascript'>
        code = "<script type='text/javascript' src=''></script>";
        code = code.replace(/&lt;/g,"<");
        code = code.replace(/&gt;/g,">");
        document.write(code);
</script>
解決方案一:
<script type='text/javascript'>
    document.write("<script type='text/javascript' src=''>/</script>")
</script>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.