XML DOM ownerElement 屬性
定義和用法
ownerElement
屬性返回屬性所附屬到的元素節點。
語法
attrObject.ownerElement
實例
下面的代碼將 "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].ownerElement + "<br>" + x.item(0).attributes[0].ownerElement .nodeName + "<br>" + x.item(0).attributes[0].ownerElement .nodeType; }