--- title: DOMImplementation.createDocument() slug: Web/API/DOMImplementation/createDocument translation_of: Web/API/DOMImplementation/createDocument ---
{{ApiRef("DOM")}}
DOMImplementation.createDocument()
方法创建并返回一个 {{domxref("XMLDocument")}}对象.
doc = document.implementation.createDocument(namespaceURI, qualifiedNameStr, documentType);
null
.DocumentType
默认为null.var doc = document.implementation.createDocument ('http://www.w3.org/1999/xhtml', 'html', null); var body = document.createElementNS('http://www.w3.org/1999/xhtml', 'body'); body.setAttribute('id', 'abc'); doc.documentElement.appendChild(body); alert(doc.getElementById('abc')); // [object HTMLBodyElement]
规范 | 状态 | 备注 |
---|---|---|
{{SpecName('DOM WHATWG', '#dom-domimplementation-createdocument', 'DOMImplementation.createDocument')}} | {{Spec2('DOM WHATWG')}}[现时标准] |
将 |
{{SpecName('DOM3 Core', 'core.html#Level-2-Core-DOM-createDocument', 'DOMImplementation.createDocument')}} | {{Spec2('DOM3 Core')}}[过时] | 自{{SpecName("DOM2 Core")}}无改变 |
{{SpecName('DOM2 Core', 'core.html#Level-2-Core-DOM-createDocument', 'DOMImplementation.createDocument')}} | {{Spec2('DOM2 Core')}}[过时] | 初始定义. |
{{Compat("api.DOMImplementation.createDocument")}}