property“getter object(DOMString name);”在文档IDL中

时间:2016-08-25 07:42:30

标签: html5 dom specifications w3c idl

HTML 5.1 Specification在文档IDL中定义了奇怪的属性。

getter object (DOMString name);

这不是一个错字,我不明白如何使用它。

1 个答案:

答案 0 :(得分:2)

Document接口的WebIDL定义的那一部分指定它具有named property getter。它只与the section of the spec of the HTML spec that defines the supported property names for the Document interface结合使用。

它们共同指定了一些作为Document的命名属性公开的内容。

考虑以下文件:

<!doctype html>
<form name=foo></form>
<form name=bar></form>
<iframe name=bar></iframe>
<p id=baz>

如果您致电document.foo,您将获得一个元素form name=foo元素。

如果您致电document.bar,您将收到包含form name=bar元素和iframe name=bar元素的集合。

如果你致电document.baz,你会回来undefined

所有这种行为的原因是,section of the HTML spec defining the supported property names for the Document interface指定可以将form[name]值和iframe[name]值作为Document

的命名属性进行访问

并且that spec section还表示如果Document命名属性只匹配一个元素,则返回该元素,但如果它匹配多个元素,则返回一个集合。

document.baz返回undefined的原因是因为that spec section未将p[id]值指定为Document的命名属性。

但是,如果您改为window.baz取回p id=baz元素。

造成这种差异的原因是:虽然WebIDL definition for Window指定它有named property getter(正如Document WebIDL所做的那样),section defining the supported property names for Window - 与类似的不同Document - 的部分指定p[id]值(任何元素的实际id值)作为a的命名属性可访问Window

相关问题