javascript - 为什么 Document.prototype.getElementsByName 存在于 Chrome 中?

标签 javascript html dom getelementsbyname

据我所知,getElementsByName是定义在HTMLDocument中的函数,HTMLDocument继承自Document,并且Document 继承自 Node

那么为什么我可以在 Chrome 中看到 Document.prototype.getElementsByName 而不是 Firefox?难道 Chrome 没有实现 DOM2 规范吗?

最佳答案

Does not Chrome implement DOM2 spec?

是的,可能不是。我猜他们至少实现了 DOM 3 , 如果不是 more current version :-)

但是,它们也没有定义 getElementsByName。那么他们是怎么得到这个的呢?它实际上是在 Document WHATWG 上的 HTML5 ( W3/partial interface ) 中指定的:

The DOM specification defines a Document interface, which this [HTML5] specification extends significantly […]

http://dev.w3.org/html5/spec-LC/dom.html#documents-in-the-dom我找到了笔记

Because the HTMLDocument interface is now obtained using binding-specific casting methods instead of simply being the primary interface of the document object, it is no longer defined as inheriting from Document.

因此这些接口(interface)的规范细节仍在进行中,并且不断变化。 请注意,浏览器甚至不应该导出任何类型的 DocumentPrototype - 规范只定义接口(interface),而不是它们的确切 EcmaScript 绑定(bind)表示。 WebIDL does .

所以 Chrome 确实遵循较新的规范(但仍然有一些 HTMLDocument?),而 Firefox 实现了旧版本。然而,真正重要的是这些方法确实存在在每个 window.document 上——而不是它们是如何到达那里的:-)

关于javascript - 为什么 Document.prototype.getElementsByName 存在于 Chrome 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21771768/

相关文章:

javascript - CSRF token 丢失或不正确 django

javascript - 减小窗口宽度时使div消失?

html - 什么是评论的反弹黑客?

javascript - 在子元素的指令中获取 CSS 属性

javascript - 在 angularJS 中如何处理 $http.post 的异步返回?

javascript - 我可以使用 CSS 绘制诸如命运之轮之类的东西吗?

html - 垂直对齐 :top not working in td with multiple elements

android - 无法从 URL 获取 html 代码

javascript - 无法将解析后的字符串附加到 dom

python - 使用 xml.dom.minidom 从 Mysql XML 转储中提取数据