XML DOM ownerDocument 屬性
❮ 元素物件
示例
以下程式碼片段將“books.xml”載入到 xmlDoc 中,並從第一個 <title> 元素的屬主文件中獲取名稱和節點型別
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
var xmlDoc = xml.responseXML;
var x = xmlDoc.getElementsByTagName("title")[0].ownerDocument;
document.getElementById("demo").innerHTML =
"節點名稱: " + x.nodeName +
" (nodetype: " + x.nodeType + ")"
}
上面程式碼的輸出將是
節點名: #document (節點型別: 9)
自己動手試一試 »
定義和用法
ownerDocument 屬性返回所選元素所屬的文件物件。
語法
elementNode.ownerDocument
❮ 元素物件