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?