据我所知,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)的规范细节仍在进行中,并且不断变化。 请注意,浏览器甚至不应该导出任何类型的 WebIDL does .DocumentPrototype
- 规范只定义接口(interface),而不是它们的确切 EcmaScript 绑定(bind)表示。
所以 Chrome 确实遵循较新的规范(但仍然有一些 HTMLDocument
?),而 Firefox 实现了旧版本。然而,真正重要的是这些方法确实存在在每个 window.document
上——而不是它们是如何到达那里的:-)
关于javascript - 为什么 Document.prototype.getElementsByName 存在于 Chrome 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21771768/