DOMImplementation.createDocument()

DOMImplementation.createDocument()方法创建并返回一个 XMLDocument对象.

语法

doc = document.implementation.createDocument(namespaceURI, qualifiedNameStr, documentType);

参数

namespaceURI
被创建的DOMString 文档的namespace URI 是namespace URI ,如果文档不属于任何namespace URI 就为null.
qualifiedNameStr
 DOMString 是否包含要创建文档的限定名称,即可选的前缀和冒号,以及本地的根元素。
documentType 可选
文档的 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]

规范

规范 状态 备注
DOM
DOMImplementation.createDocument
Living Standard[现时标准]

createDocument() 的返回类型从 Document 修改为XMLDocument.
createDocument()的第三个参数,文档类型,现在是可选的,默认为null.

Document Object Model (DOM) Level 3 Core Specification
DOMImplementation.createDocument
Obsolete[过时] Document Object Model (DOM) Level 2 Core Specification无改变
Document Object Model (DOM) Level 2 Core Specification
DOMImplementation.createDocument
Obsolete[过时] 初始定义.

浏览器支持

Update compatibility data on GitHub
DesktopMobile
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung Internet
createDocumentChrome Full support YesEdge Full support 12Firefox Full support YesIE Full support 9Opera Full support YesSafari Full support YesWebView Android Full support YesChrome Android Full support YesFirefox Android Full support YesOpera Android Full support YesSafari iOS Full support YesSamsung Internet Android ?

Legend

Full support  
Full support
Compatibility unknown  
Compatibility unknown

另请参见