2
章节2
渲染用户界面 (UI)
为了理解 React 的工作原理,我们首先需要了解浏览器如何解释你的代码来创建(或渲染)用户界面 (UI)。
当用户访问一个网页时,服务器会向浏览器返回一个 HTML 文件,可能看起来像这样


然后浏览器读取 HTML 并构建文档对象模型 (DOM)。
什么是 DOM?
DOM 是 HTML 元素的对象表示。它充当代码和用户界面之间的桥梁,并具有树状结构,包含父子关系。


你可以使用 DOM 方法和 JavaScript 来监听用户事件并操作 DOM,通过选择、添加、更新和删除用户界面中的特定元素。DOM 操作不仅允许你定位特定元素,还可以更改其样式和内容。
在下一节中,你将学习如何使用 JavaScript 和 DOM 方法。
其他资源
这是否有帮助?