XML DOM isId 屬性
定義和用法
如果已知屬性屬于 ID 類型(例如包含其所有者元素的標識符),則 isId
屬性返回 true,否則返回 false。
語法
attrObject.isId
實例
下面的代碼將 "books.xml" 加載到 xmlDoc 中,并返回類別屬性是否為 <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; }