javascript - JavaScript 和 DOM 究竟是如何工作的?

标签 javascript dom

<分区>

为什么 JavaScript 需要 DOM? JavaScript 究竟是如何工作的?

最佳答案

While JavaScript is the programming language which will allow you to operate on the DOM objects and to manipulate them programmatically, the DOM will provide you with methods and properties to retrieve, modify, update, and delete parts of the document you are working on. For example, you may retrieve the value of an HTML text input control as a string using the DOM. You could then use the JavaScript "+" operator to concatenate that string with another one in order to make a meaningful sentence. You would then use the DOM "alert()" method to display the string in a dialog to the user. See also the examples below.

If a Web page were a piece of imported Swedish furniture, the DOM would be the illustrations of the parts - the shelves, bolts, Allen wrenches and screwdrivers. It's possible to write instructions on how to put the parts together and use the parts in any number of languages, but you'll only use the ones written in the one you understand. The manual makes it easy to put the furniture together by using written instructions (JavaScript) to reference illustrations of objects (DOM) which represent actual objects (browser's rendering engine). (Thanks to Jonathan for the analogy!)

What's this "language-neutral" hype with the DOM? Why is the DOM language-neutral if the only language ever used to access it is JavaScript? Well, that is not quite correct. For example, Mozilla uses the DOM internally both in C++ and JavaScript for its user interface. The editor, for instance, uses the DOM extensively in order to insert, modify, and delete the HTML that you are seeing when you compose a page in the Composer module. Other known implementations of the DOM include Perl, Java, ActiveX, Python, and probably others. This is of course only possible thanks to the language-neutrality of the DOM.

更多详情查看HEREWiki .

关于javascript - JavaScript 和 DOM 究竟是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3299109/

相关文章:

javascript - 有条件地从数组中删除重复项

javascript - 我需要从网站中选择一个元素 "x",但该网站加载元素“x”太慢

javascript - Bootstrap 3 单选按钮双切换

javascript - 如何在网页上制作所见即所得的部分?

java - 在java中从XML中获取子节点的值

javascript - 我如何组织在 NestJs 服务中抛出业务逻辑异常?

JavaScript 错误,根据其他复选框的结果更新复选框/按钮

javascript - Rx debounce operator with first 和 last

javascript - 运行嵌入在 AJAX 加载元素中的 JS 时等待加载?

javascript - 如何计算 Angular 中水平滚动 div 的内容