DOMImplementation對象createDocument()
方法用於創建具有document
元素的指定類型的DOM Document
對象。
語法
以下是createDocument()
方法的語法。
Document doc = document.implementation.createDocument(namespaceURI, qualifiedNameStr, documentType);
參數
namespaceURI
是要創建的文檔元素的名稱空間URI或null
。qualifiedName
是要創建的文檔元素的限定名稱或null
。doctype
是要創建的文檔類型或null
。- 此方法返回一個帶有
document
元素的新Document
對象。
示例
下麵的示例演示了createDocument()
方法的用法 -
<!DOCTYPE html>
<html>
<meta charset="utf-8"/>
<head>
</head>
<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對象
下一篇:
DOM DocumentType對象