javascript - Document 和 document 和有什么不一样?

标签 javascript html dom

<分区>

enter image description here

这是 index on the left 的图像在 Mozilla 开发者网络上。

我想问的是:

Documentdocument 有什么区别?

我问的原因是:

我总是按如下方式检索元素(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/

相关文章:

javascript - 如何将星期一设置为 Wijmo 日历中一周的第一天

dom - 这是 JSNI 中 $doc.getElementById ("id") 和 document.getElementById ("id") 之间的区别

选择选项后,Javascript/Jquery 更改 Select 类

javascript - 在 JavaScript 的 Web Worker (worker.js) 中创建图像

html - 定位、边距、CSS

javascript - HTML 下拉选择值

javascript - 在 JavaScript 中组合鼠标事件

java - 如何使用 Java DOM 克隆整个文档?

javascript - 滚动条在 Internet Explorer 10 中显示不正确

javascript - 使用 jQuery 无限滚动静态页面