DOMImplementation.createDocument() method creates and returns an XMLDocument .

句法

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

参数

namespaceURI
DOMString containing the namespace URI of the document to be created, or null if the document doesn't belong to one.
qualifiedNameStr
DOMString containing the qualified name, that is an optional prefix and colon plus the local root element name, of the document to be created.
documentType 可选

Is the DocumentType of the document to be created. It defaults to 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
The definition of 'DOMImplementation.createDocument' in that specification.
实时标准 Modified the return type of createDocument() from Document to XMLDocument .
The third argument of createDocument() , doctype , is now optional and default to null .
DOM (文档对象模型) 3 级核心规范
The definition of 'DOMImplementation.createDocument' in that specification.
过时 无变化自 DOM (文档对象模型) 级别 2 核心规范
DOM (文档对象模型) 级别 2 核心规范
The definition of 'DOMImplementation.createDocument' in that specification.
过时 初始定义。

浏览器兼容性

The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
createDocument Chrome Yes Edge 12 Firefox Yes IE 9 Opera Yes Safari Yes WebView Android Yes Chrome Android Yes Firefox Android Yes Opera Android Yes Safari iOS Yes Samsung Internet Android Yes

图例

完整支持

完整支持

另请参阅

元数据

  • 最后修改: