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; }