XML DOM hasAttributes() 方法

定義和用法

如果當前元素節點擁有任何屬性,則 hasAttributes() 返回 true,否則返回 false。

語法:

hasAttributes()

實例

在所有的例子中,我們將使用 XML 文件 books.xml,以及 JavaScript 函數 loadXMLDoc()

下面的代碼片段檢查 "books.xml" 中的第一個 <book> 元素是否擁有屬性:

xxmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName('book')[0];
document.write(x.hasAttributes());

以上代碼的輸出:

true