<分区>
这是 index on the left 的图像在 Mozilla 开发者网络上。
我想问的是:
Document
和 document
有什么区别?
我问的原因是:
我总是按如下方式检索元素(document
带有一个小的 d
):
document.getElementById("#id");
MDN 将其列为如下(Document
大写 D
):
Document.getElementById("#id");
标签 javascript html dom
<分区>
这是 index on the left 的图像在 Mozilla 开发者网络上。
我想问的是:
Document
和 document
有什么区别?
我问的原因是:
我总是按如下方式检索元素(document
带有一个小的 d
):
document.getElementById("#id");
MDN 将其列为如下(Document
大写 D
):
Document.getElementById("#id");
最佳答案
document 是在浏览器中加载的 html 页面的实际对象。这是一个 DOM 对象。
Document 是函数(准确地说是DOM 接口(interface)),将用于创建文档对象。这个“文档”是由浏览器程序实现的。这将我们的 HTML 文件作为输入并创建“文档”对象。
Document.getElementById(..) -> wrong. This wont work.
Document.prototype.getElementById(..) This is the right way
请引用此链接 - Reference link 文档实现特定于每个浏览器。但可以延长。也检查这篇文章。 http://perfectionkills.com/whats-wrong-with-extending-the-dom/
文档对象可能来自浏览器基于文件类型的单独实现。对于 HTML,原型(prototype)将是“HTMLDocumentPrototype”(使用 Document 接口(interface)),而对于 XML,它只是一个“对象”并且没有附加原型(prototype)。这可能因浏览器而异,因为实现是特定的。
关于javascript - Document 和 document 和有什么不一样?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23052135/