JS中Document節點總結

來源:互聯網
上載者:User

標籤:form   常用   instr   選擇   ima   XML   url   屬性   link   

  document對象是documentHTML的一個執行個體,也是window對象的一個屬性,因此可以將document對象作為一個全域對象來訪問。

  Document節點的子節點可以是DocumentType,Element,ProcessingInstruction或Comment。ProcessingInstruction 對象可表示處理指示。這個不常用的介面表示 XML 文檔中的一個處理指示(或 PI)。使用 HTML 文檔的程式設計者不會遇到 ProcessingInstruction 節點,所以就不多介紹了,DocumentType我們可以通過doctype屬性來訪問他的資訊。Comment作為注釋也不多說了,這裡只說一下Element。

  1.html元素和body元素

  document.documentElement來擷取html元素,document.body來擷取body元素。

  2.文檔資訊

  document.title擷取文檔標題。

  document.URL屬性包含頁面完整的URL比如:{協議}://{使用者名稱}:{密碼}@{主機名稱}:{連接埠號碼}/{路徑}/{檔案}?{參數}

  document.domain屬性只包括頁面的網域名稱。

  document.referrer屬性是從什麼頁面跳到當前頁面的。

  3.擷取元素

    1)getElementById();

    2)getElementsByTagName();

    3)getElementsByName();

    4)getElementsByClassName();

    5)querySelector();擷取單個元素,()中可以是css選取器的標準形式相容到css2.

    6)querySelectorAll();擷取元素集合,()中可以是css選取器的標準形式相容到css2.

  4.特殊集合

    1)document.anchors:包含文檔中所有帶那麼特性的<a>元素。

    2)document.forms:包含文檔中所有的<img>元素,與document.getElementByTagName("form")的到的結果相同。

    3)document.images:包含文檔中所有的<img>元素,與document.getElementByTagName("img")的到的結果相同。

    4.document.links:包含文檔中所有帶href特性的<a>元素。

  5.文檔寫入

    1)write():按原樣寫入。

    2)writeln():在字串的末尾添加一個分行符號。

    3)open():開啟網頁的輸出資料流。

    4)close():關閉網頁的輸出資料流。  

    

   

  

  

JS中Document節點總結

聯繫我們

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