javascript &DOM基礎(一)

來源:互聯網
上載者:User

  本文將DOM和javascript的一些常用法介紹給大家!

  1、innerText、innerHTML、outerText、outerHTML區別

    功能:

innerHTML 設定或擷取位於對象起始和結束標籤內的 HTML .
outerHTML 設定或擷取對象及其內容的 HTML 形式 .
innerText 設定或擷取位於對象起始和結束標籤內的文本 .
outerText 設定(包括標籤)或擷取(不包括標籤)對象的文本 .

 樣本: 

   以標籤<div id="test"><b>hello world!</b></div>為例進行說明:

   innerText顯示的內容為:hello world!

   innerHTML顯示的內容為:<b>hello world!</b>

    outerText顯示的內容為:hello word!

   outerHTML顯示的內容為:<div id="test"><b>hello world!</b></div>

 說明

   innerHTML是W3C標準支援各種瀏覽器,而innerText、outerText、outerHTML是IE特有的,在FF中可以用textContent替換innerText

2、document.readyState

 功能

   判斷頁面的下載狀態

 樣本

  document.onreadystatechange = function()
        {
          
                if (document.readyState == "complete")
                {
                        //do sth;
                }
        }

   說明

   該屬性僅IE中可以使用。

3、insertAdjacentHTML

 功能

  可以在指定的地方插入html內容和常值內容。

 樣本
  <html>
    <head>
        <script language="javascript">
            function test(){
            var obj = document.getElementById("test");
                obj.insertAdjacentHTML("afterEnd", "<br><input name=\"a\" >");
             }
        </script>
    </head>
    <body>
        <input id="test" name="test" type="text" value="" onclick="test()">
    </body>
</html>

 說明

FF中沒有該屬性。

 


   

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.