XML DOM hasAttributes() 方法
❮ Node 物件
示例
以下程式碼片段將“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();
}
輸出
true
自己動手試一試 »
定義和用法
如果指定節點有任何屬性,hasAttributes() 方法返回 true,否則返回 false。
注意:如果指定的節點不是元素節點,則返回值始終為 false。
瀏覽器支援
所有主流瀏覽器都支援 hasAttributes() 方法。
注意:Internet Explorer 9 及更早版本不支援 hasAttributes() 方法。
語法
nodeObject.hasAttributes()
引數
無。
返回值
型別 | 描述 |
---|---|
布林值 | 如果指定節點有任何屬性,則返回 true,否則返回 false |
技術詳情
DOM 版本 | Core Level 2 Node Object |
---|
❮ Node 物件