为什么Chrome中存在Document.prototype.getElementsByName? [英] Why does Document.prototype.getElementsByName exist in Chrome?

查看:133
本文介绍了为什么Chrome中存在Document.prototype.getElementsByName?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道, getElementsByName 是在 HTMLDocument HTMLDocument 继承自文档文档继承自 Node



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

解决方案


Chrome是否实现DOM2规范?


是的,可能不是。我猜他们至少实现了 DOM 3 ,如果不是更多 当前版本: - )



但是,这些没有定义 getElementsByName 。那么他们是怎么得到的呢它实际上是在HTML5中指定的( WHATWG / W3 )上的文件 部分界面


DOM规范定义了一个Document接口,这个[HTML5]规范显着扩展[...]




而在 http://dev.w3.org/html5/spec-LC/dom.html#documents-in-the-dom 我发现了这个笔记



因为HTMLDocument接口现在是使用绑定特定的转换方法而不是简单地作为文档对象的主要接口获得的,所以它不再被定义为继承自Document。




所以这些接口的规范细节仍在进行中,不一样。注意,浏览器甚至不应该导出任何类型的 DocumentPrototype - 规范只定义接口,而不是精确的EcmaScript绑定表示 WebIDL does

$ b因此,Chrome会遵循较新的规范(但是仍然有一些 HTMLDocument ?),而Firefox实现了较旧的版本。但是,这些方法在每个 window.document 上确实存在只是真的很重要 - 而不是他们到达那里: - )


As I know,getElementsByName is a function defined in HTMLDocument,and HTMLDocument inherits from Document,and Document inherits from Node.

So why I can see Document.prototype.getElementsByName in Chrome but not Firefox?Does not Chrome implement DOM2 spec?

解决方案

Does not Chrome implement DOM2 spec?

Yeah, probably not. I'd guess they at least implement DOM 3, if not a more current version :-)

However, those don't define a getElementsByName either. So how did they get this? It is actually specified in HTML5 (WHATWG/W3) on the Document partial interface:

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

And at http://dev.w3.org/html5/spec-LC/dom.html#documents-in-the-dom I found the note

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.

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.

So Chrome does follow the newer specs (but still has some HTMLDocument?), while Firefox implements an older version. However, it only really matters that these methods do exist on every window.document - not how they got there :-)

这篇关于为什么Chrome中存在Document.prototype.getElementsByName?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆