For faster navigation, this Iframe is preloading the Wikiwand page for 文档对象模型.

文档对象模型

此條目形似新聞稿,或帶有過度的宣傳性語調。 (2021年8月9日)請協助以中立的觀點撰寫本條目,非常明显的广告内容请加入((Delete|G11))來提请删除
文档对象模型
在HTML文档中DOM层级的例子
首次出版1998年10月1日,​25年前​(1998-10-01
最新版本DOM4[1]
2015年11月19日,​8年前​(2015-11-19
组织World Wide Web Consortium, WHATWG
基础标准WHATWG DOM Living Standard
W3C DOM4
缩写DOM

文件物件模型(英語:Document Object Model,缩写DOM),是W3C组织推薦的处理可扩展置标语言超文本标记语言的标准程式接口。

Document Object Model的歷史可以追溯至1990年代後期微軟與Netscape的“瀏覽器大戰”(browser wars),雙方為了在JavaScriptJScript一決生死,於是大規模的賦予瀏覽器強大的功能。微軟在網頁技術上加入了不少專屬事物,既有VBScriptActiveX、以及微軟自家的DHTML格式等,使不少網頁使用非微軟平台及瀏覽器無法正常顯示。DOM即是當時醞釀出來的傑作。

DOM (Document Object Model) 译为文档对象模型,是 HTML 和 XML 文档的编程接口。

HTML DOM 定义了访问和操作 HTML 文档的标准方法。

DOM 以树结构表达 HTML 文档。

W3C DOM 标准被分为 3 个不同的部分:[2]

  • 核心 DOM - 针对任何结构化文档的标准模型
  • XML DOM - 针对 XML 文档的标准模型
  • HTML DOM - 针对 HTML 文档的标准模型

XML DOM 定义了所有 XML 元素的对象属性,以及访问它们的方法

HTML DOM

简介

HTML DOM 是:[3]

  • HTML 的标准对象模型
  • HTML 的标准编程接口
  • W3C 标准

HTML DOM 定义了所有 HTML 元素的对象属性,以及访问它们的方法

换言之,HTML DOM 是关于如何获取、修改、添加或删除 HTML 元素的标准。

DOM方法

编程接口

可通过 JavaScript (以及其他编程语言)对 HTML DOM 进行访问。

所有 HTML 元素被定义为对象,而编程接口则是对象方法和对象属性。

方法是您能够执行的动作(比如添加或修改元素)。

属性是您能够获取或设置的值(比如节点的名称或内容)。 一些常用的 HTML DOM 方法:

  • getElementById(id) - 获取带有指定 id 的节点(元素)
  • appendChild(node) - 插入新的子节点(元素)
  • removeChild(node) - 删除子节点(元素)

DOM对象

一些常用的 HTML DOM 属性:

  • innerHTML - 节点(元素)的文本值
  • parentNode - 节点(元素)的父节点
  • childNodes - 节点(元素)的子节点
  • attributes - 节点(元素)的属性节点

DOM属性

  • nodeType 属性
  • nodeValue 属性
  • innerHTML 属性

標準化

WHATWG DOM

W3C對DOM進行標準化的動作,目前已經推行至第四代。

Level 1

Level 2

Level 3

Level 4

参考文献

  1. ^ All versioning refers to W3C DOM only.
  2. ^ Document Object Model (DOM) Specifications. www.w3.org. [2022-09-29]. (原始内容存档于2022-06-02). 
  3. ^ JavaScript HTML DOM. www.w3schools.com. [2022-09-29]. (原始内容存档于2022-10-22) (美国英语). 

外部連結

参见

  • SAX:Simple API for XML
{{bottomLinkPreText}} {{bottomLinkText}}
文档对象模型
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?