DOM到底是什么?从DOM中获取的对象是什么? [英] what exactly is the DOM? and what is an object as taken from the DOM?

查看:126
本文介绍了DOM到底是什么?从DOM中获取的对象是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我了解一些Javascript,最近开始尝试通过代码学院课程将其与HTML绑定。在以下代码中:

I know a bit of Javascript and have recently started trying to tie it into HTML with the code academy course. in the following code:

function sayHello(name){
    document.getElementById("result").innerHTML = 'Hello ' + name + '!';
}

以上代码中的文档是DOM吗?

The "document" in the above code is the DOM?

这意味着getElements是文档的属性(函数),而innerHTML是getElements函数的函数...。对吗?

That would mean that getElements is a property (function) of document, and that innerHTML is a function of the getElements function.... right?

如果我正确地看到了这一点,那么DOM对象怎么可能具有javascript属性/功能?

If I am seeing this correctly, how is it possible that DOM objects have javascript properties/functions?

推荐答案

文档 DOM



简短答案

是的,从某种意义上说是它的根。

Yes, in the sense that it is the root of it.

答案略长

浏览器公开的是文档对象模型(DOM)到JavaScript运行时,以允许JavaScript代码操纵页面(其节点和关联的元数据)。 文档是DOM的一部分。

The Document Object Model (DOM) is what the browser exposes to the JavaScript runtime to allow JavaScript code to manipulate the page (its nodes and associated metadata). document is one part of the DOM.

简短答案

他们没有。

答案略长

DOM实际上尚未在JavaScript中管理。通常,它完全由单独的引擎管理,以较低级的语言(例如C ++或Rust)编写(对于Mozilla的Servo项目而言)。 JavaScript运行时也 用较低级的语言编写(同样,C ++很有可能),并且DOM的某些属性暴露给JavaScript运行时如果它们是原生JavaScript对象。它们不是事实,使所有有趣的事情成为可能……并且通常使这些DOM对象成为并非总是像您期望的那样,真实的 JavaScript对象会表现出行为(例如,IE 8中的 typeof querySelectorAll 返回对象,而不是函数 正如人们合理预期的那样。)

The DOM is not actually managed in JavaScript (yet). It is typically managed by a separate engine altogether, written in a lower-level language like C++ or Rust (in the case of Mozilla's Servo project). The JavaScript runtime is also written in a lower-level language (again, C++ is most likely) and certain attributes of the DOM are exposed to the JavaScript runtime as if they were native JavaScript objects. The fact that they are not makes all kinds of interesting things possible ... and generally make it so that these DOM objects do not always behave as you would expect "real" JavaScript objects to behave (for example typeof querySelectorAll in IE 8 returns "object", not "function" as one would reasonably expect).

这篇关于DOM到底是什么?从DOM中获取的对象是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆