Skip to content

DOM

一句话解释

DOM (Document 对象 Model) 是树-如 representation 的 HTML document 那个 JavaScript 能读取 and 修改.

用大白话说

When the browser loads an HTML page, it parses the markup and builds an in-memory tree of objects — one for every element, attribute, and piece of text. This tree is the DOM. It is the live, programmable representation of the page.

JavaScript can interact with the DOM to change the page without reloading. You can add or remove elements, change text, update styles, and respond to user events — all by manipulating DOM nodes. This is how every interactive web feature works, from dropdown menus to single-page apps.

The DOM is a standard API defined by the W3C, so the same JavaScript works across browsers. Common entry points are document.getElementById(), document.querySelector(), and 元素.addEventListener().

示例

javascript
// Change the text of an element
const heading = document.getElementById("title");
heading.textContent = "Hello, DOM!";

// Add a new element
const p = document.createElement("p");
p.textContent = "I was added by JavaScript.";
document.body.appendChild(p);

JavaScript uses DOM API 到更改文本内容 and append 新元素到 page.

工作原理

  1. The browser parses the HTML and builds the DOM tree.
  2. JavaScript queries the tree with methods like getElementById.
  3. You modify nodes — change text, styles, attributes, or add/remove children.
  4. The browser re-renders the affected part of the page automatically.

相关术语

相关资源

相关课程

  • 浏览器

    如何浏览器渲染 HTML 到 DOM

  • DOM

    Manipulating DOM 使用 JavaScript

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误

← 返回术语表