語法
js
createDocument(namespaceURI, qualifiedName)
createDocument(namespaceURI, qualifiedName, documentType)
引數
namespaceURI-
一個字串,包含要建立的文件的名稱空間 URI,如果文件不屬於任何名稱空間,則為
null。 qualifiedName(限定名稱)-
一個字串,包含限定名稱(即可選的字首和冒號,再加上本地根元素名稱),用於要建立的文件。
null值被視為與空字串 ("") 相同。 documentType可選-
要建立的文件的
DocumentType。預設為null。
返回值
新建立的 XMLDocument。
示例
js
const doc = document.implementation.createDocument(
"http://www.w3.org/1999/xhtml",
"html",
null,
);
const 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-createdocument② |
瀏覽器相容性
載入中…
另見
- 它所屬的
DOMImplementation介面。