--- title: Node.ownerDocument slug: Web/API/Node/ownerDocument tags: - API - DOM - Gecko - Property - 属性 translation_of: Web/API/Node/ownerDocument ---
Node.ownerDocument 只读属性会返回当前节点的顶层的 document 对象。
document = node.ownerDocument
document
是当前元素的 document
对象,其是当前元素的祖先。// 得到p元素所在文档的HTML节点 d = p.ownerDocument; html = d.documentElement;
被此属性返回的 document
对象是在实际的HTML文档中的所有子节点所属的主对象。如果在文档节点自身上使用此属性,则结果是null
。
Specification | Status | Comment |
---|---|---|
{{SpecName("DOM4", "#dom-node-ownerdocument", "Node.ownerDocument")}} | {{Spec2("DOM4")}} | |
{{SpecName("DOM3 Core", "core.html#node-ownerDoc", "Node.ownerDocument")}} | {{Spec2("DOM3 Core")}} | No change |
{{SpecName("DOM2 Core", "core.html#node-ownerDoc", "Node.ownerDocument")}} | {{Spec2("DOM2 Core")}} | Initial definition |
{{ CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }}[1] | 6.0[2] | {{ CompatVersionUnknown() }} | {{ CompatVersionUnknown() }} |
Feature | Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|
Basic support | {{ CompatUnknown() }} | {{ CompatUnknown() }}[1] | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} |
[1] 从 Gecko 9.0 {{ geckoRelease("9.0") }} 开始, 一个由脚本生成的
DocumentType类型的节点(节点类型{{ domxref("Node.nodeType") }}的值为 Node.DOCUMENT_TYPE_NODE
也就是 10)的ownerDocument
属性的值不再是null. 而是调用document.implementation.createDocumentType()
方法创建该节点的文档节点.
[2] http://msdn.microsoft.com/en-us/library/ie/ms534315(v=vs.85).aspx