XML DOM ownerDocument 屬性
❮ Attr 物件
示例
以下程式碼片段載入 "books.xml" 到 xmlDoc 並返回第一個 category 屬性節點的根元素
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('book');
document.getElementById("demo").innerHTML =
x.item(0).attributes[0].ownerDocument + "<br>" +
x.item(0).attributes[0].ownerDocument.nodeName + "<br>" +
x.item(0).attributes[0].ownerDocument.nodeType;
}
上面程式碼的輸出將是
[object XMLDocument]
#document
9
自己動手試一試 »
定義和用法
ownerDocument 屬性返回一個節點的根元素(文件物件)。
語法
attrObject.ownerDocument
❮ Attr 物件