我所知,getElementsByName
是一个定义在中的函数HTMLDocument
,and HTMLDocument
继承自Document
,and Document
继承自Node
.
那为什么我能看到Document.prototype.getElementsByName
在 Chrome 中,但在 Firefox 中则不然?Chrome 没有实现 DOM2 规范吗?
Chrome 没有实现 DOM2 规范吗?
是的,可能不会。我猜他们至少实施了DOM 3 http://www.w3.org/TR/DOM-Level-3-Core/core.html#i-Document,如果不是more http://dom.spec.whatwg.org/ 当前版本 http://www.w3.org/TR/dom/ :-)
然而,这些并没有定义getElementsByName
任何一个。那么他们是怎么得到这个的呢?它实际上是在 HTML5 中指定的(WHATWG http://www.whatwg.org/specs/web-apps/current-work/multipage/dom.html#document/W3 http://www.w3.org/TR/html5/dom.html#the-document-object)在Document
部分接口 http://www.w3.org/TR/WebIDL/#dfn-partial-interface:
DOM 规范定义了一个 Document 接口,该 [HTML5] 规范显着扩展了该接口 [...]
And at http://dev.w3.org/html5/spec-LC/dom.html#documents-in-the-dom http://dev.w3.org/html5/spec-LC/dom.html#documents-in-the-dom我找到了注释
由于 HTMLDocument 接口现在是使用特定于绑定的转换方法获得的,而不是简单地作为文档对象的主接口,因此它不再定义为从 Document 继承。
So the specification details of these interfaces are still in progress, and varying. Notice that browsers are not even supposed to export any kind of DocumentPrototype
- the specs do only define interfaces, not the exact EcmaScript binding representation of them. WebIDL does http://www.w3.org/TR/WebIDL/#es-interfaces.
所以 Chrome 确实遵循了较新的规范(但仍然有一些HTMLDocument
?),而 Firefox 实现的是旧版本。然而,真正重要的是这些方法do exist在每一个window.document
- 不是他们如何到达那里的:-)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)