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().
示例
// 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.
工作原理
- The browser parses the HTML and builds the DOM tree.
- JavaScript queries the tree with methods like
getElementById. - You modify nodes — change text, styles, attributes, or add/remove children.
- The browser re-renders the affected part of the page automatically.
相关术语
相关资源
解读错误信息
用大白话解释常见错误——什么意思、为什么发生、如何修复。