DOM
DOMImplementation.createDocument()方法创建并返回一个 XMLDocument对象。
语法
doc = document.implementation.createDocument(namespaceURI, qualifiedNameStr, documentType);
参数
- namespaceURI
- : 被创建的String 文档的 namespace URI 是 namespace URI ,如果文档不属于任何 namespace URI 就为
null.
- : 被创建的String 文档的 namespace URI 是 namespace URI ,如果文档不属于任何 namespace URI 就为
- qualifiedNameStr
- : String 是否包含要创建文档的限定名称,即可选的前缀和冒号,以及本地的根元素。
- 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]
规范
浏览器兼容性
参见
- 归属它的 DOMImplementation 接口。
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
