1. 面向开发者的 Web 技术
  2. Web API
  3. DOMImplementation
  4. DOMImplementation.createDocument()

此页面由社区从英文翻译而来。了解更多并加入 MDN Web Docs 社区。

View in English Always switch to English

DOMImplementation.createDocument()

基线 广泛可用

自 2015年7月 起,此特性已在主流浏览器中得到支持,可在大多数设备和浏览器版本中正常使用。

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

语法

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

参数

namespaceURI

被创建的String 文档的 namespace URI 是 namespace URI ,如果文档不属于任何 namespace URI 就为null.

qualifiedNameStr

String 是否包含要创建文档的限定名称,即可选的前缀和冒号,以及本地的根元素。

documentType 可选

文档的 DocumentType 默认为 null.

例子

js
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
# ref-for-dom-domimplementation-createdocument2

浏览器兼容性

参见

帮助改进 MDN

了解如何参与贡献

此页面最后更新于 ,由 MDN 贡献者更新。

AltStyle によって変換されたページ (->オリジナル) /