- XML DOM 基礎
- XML DOM - 首頁
- XML DOM - 概述
- XML DOM - 模型
- XML DOM - 節點
- XML DOM - 節點樹
- XML DOM - 方法
- XML DOM - 載入
- XML DOM - 遍歷
- XML DOM - 導航
- XML DOM - 訪問
- XML DOM 操作
- XML DOM - 獲取節點
- XML DOM - 設定節點
- XML DOM - 建立節點
- XML DOM - 新增節點
- XML DOM - 替換節點
- XML DOM - 刪除節點
- XML DOM - 克隆節點
- XML DOM 物件
- DOM - Node 物件
- DOM - NodeList 物件
- DOM - NamedNodeMap 物件
- DOM - DOMImplementation
- DOM - DocumentType 物件
- DOM - ProcessingInstruction
- DOM - Entity 物件
- DOM - EntityReference 物件
- DOM - Notation 物件
- DOM - Element 物件
- DOM - Attribute 物件
- DOM - CDATASection 物件
- DOM - Comment 物件
- DOM - XMLHttpRequest 物件
- DOM - DOMException 物件
- XML DOM 有用資源
- XML DOM - 快速指南
- XML DOM - 有用資源
- XML DOM - 討論
DOM - DOMImplementation 物件方法 - createdocument
createDocument() 方法用於建立一個指定型別的 DOM 文件物件及其文件元素。
語法
以下是 createDocument() 方法的語法。
Document doc = document.implementation.createDocument (namespaceURI, qualifiedNameStr, documentType);
namespaceURI 是要建立的文件元素的名稱空間 URI 或 null。
qualifiedName 是要建立的文件元素的限定名稱或 null。
doctype 是要建立的文件型別或 null。
此方法返回一個新的帶有其文件元素的 Document 物件。
示例
以下示例演示了 createDocument() 方法的使用。
<!DOCTYPE html>
<html>
<body>
<script>
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', 'Company');
doc.documentElement.appendChild(body);
document.write(doc.getElementById('Company')); // [object HTMLBodyElement]
</script>
</body>
</html>
執行
將此檔案儲存為伺服器路徑上的 domimplementation_createdocument.htm(此檔案和 node.xml 應位於伺服器上的同一路徑)。我們將得到如下所示的輸出:
[object HTMLBodyElement]
dom_domimplementation_object.htm
廣告