XML DOM hasAttributes() 方法
定義和用法
hasAttributes() 方法會在某節(jié)點用于任何屬性時返回 true,否則返回 false。
語法:
nodeObject.hasAttributes()
實例
在所有的例子中,我們將使用 XML 文件 books.xml,以及 JavaScript 函數(shù) loadXMLDoc()。
下面的代碼片段可返回是否首個 <book> 元素用于任何的屬性:
xmlDoc=loadXMLDoc("books.xml");
var x=xmlDoc.getElementsByTagName('book')[0];
document.write(x.hasAttributes()
);
輸出:
true