XML DOM hasAttributes() 方法
定義和用法
如果當前元素節點擁有任何屬性,則 hasAttributes()
方法返回 true,否則返回 false。
語法
hasAttributes()
範例
以下代码将 "books.xml" 載入 xmlDoc 並檢查第一個 <book> 元素是否擁有任何屬性:
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')[0]; document.getElementById("demo").innerHTML = x.hasAttributes(); }