XML DOM isId 屬性
❮ Attr 物件
示例
以下程式碼片段將 "books.xml" 載入到 xmlDoc 中,並返回 category 屬性是否為 <book> 元素的 ID 屬性。
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 x, i, xmlDoc, txt;
xmlDoc = xml.responseXML;
txt = "";
x = xmlDoc.getElementsByTagName('book');
for(i = 0; i < x.length; i++) {
txt += x.item(i).attributes[0].isId + "<br>";
}
document.getElementById("demo").innerHTML = txt;
}
自己動手試一試 »
定義和用法
isId 屬性如果在屬性被識別為 ID 型別(例如,包含其所有者元素的識別符號)時返回 true,否則返回 false。
語法
attrObject.isId
❮ Attr 物件