TUTORIAL前端与浏览器FETCHED

XML DOM hasAttributes() 方法

XML DOM hasAttributes() 方法 Element 对象 定义和用法 hasAttributes() 方法在当前元素节点拥有属性时返回 TRUE,否则返回 FALSE。 语法 hasAttributes() 实例 下面的代码片段使用 loadXMLDoc() 把 'books.xml' 载入 xmlDoc 中,并检查返回第一个 <book> 元素是否拥有属..

更新于 2026/7/16

教程详情页默认 noindex。

XML DOM hasAttributes() 方法


Element 对象参考手册 Element 对象

定义和用法

hasAttributes() 方法在当前元素节点拥有属性时返回 TRUE,否则返回 FALSE。

语法

hasAttributes()


实例

下面的代码片段使用 loadXMLDoc() 把 "books.xml" 载入 xmlDoc 中,并检查返回第一个 <book> 元素是否拥有属性:

实例

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

document.write(x.hasAttributes());

输出:

true

尝试一下 »

Element 对象参考手册 Element 对象