DOM筆記(一):HTMLDocument介面,domhtmldocument

來源:互聯網
上載者:User

DOM筆記(一):HTMLDocument介面,domhtmldocument

操作HTML文檔的第一步就是擷取對文件項目的引用,每一個元素在DOM中就是一個節點,所有的元素在DOM中構成一個節點樹。

用於擷取元素節點定義的方法定義於HTMLDocument介面,window.document方法用於實現該介面,其定義的常用方法和屬性如下:

 

屬性或方法 返回值類型 說明
[getter] 任何類型 根據元素的name屬性擷取所有元素節點
all HTMLAllCollection 文檔中所有元素組成的集合,已不推薦使用
body HTMLElement 擷取<body>元素節點
head HTMLHeadElement 擷取<head>元素節點
images HTMLCollection 擷取所有<img>元素節點
embeds HTMLCollection 擷取所有<embed>元素節點
plugins HTMLCollection 等同於embeds屬性
links HTMLCollection 擷取所有帶href屬性的<a>和<area>元素節點
forms HTMLCollection 擷取所有<form>元素節點
scripts HTMLCollection 擷取所有<script>元素節點
getElementsByName() NodeList 根據元素的name屬性擷取所有元素節點
getElementsByClassName() NodeList 根據元素的class屬性擷取所有元素節點

另外,HTMLDocument介面也繼承了Core DOM的Document介面,繼承的屬性和方法如下:

屬性或方法 返回值類型 說明
documentElement Element 擷取xml或者html的根項目,在html中即<html>
getElementById() Element 根據ID屬性值擷取指定元素
getElementsByTagName() NodeList 根據元素名稱擷取所有元素節點
getElementsByTagNameNS() NodeList 根據指定的命名空間的元素名擷取所有元素節點
原文首發:http://www.ido321.com/1315.html
‘
下一篇:DOM筆記(二):Node介面

聯繫我們

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