XML DOM isId 属性
XML基础 2023-08-12 17:49:10小码哥的IT人生shichen
XML DOM isId 属性
定义和用法
如果 attribute 是 ID 类型(例如,包含了其所属的元素的标识符),则 isId 属性返回 true,否则返回 false。
语法:
attrObject.isId
实例
在所有的例子中,我们将使用 XML 文件 books.xml,以及 JavaScript 函数 loadXMLDoc()。
下面的代码片段返回 category 属性是否是 <book> 元素的 ID 属性:
xmlDoc=loadXMLDoc("/example/xdom/books.xml");
var x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
{
document.write(x.item(i).attributes[0].isId
);
document.write("<br />");
}
以上代码的输出应该是:
false
false
false
false
TIY
完整实例【isId - 获取属性是否是 ID 类型】:
<html>
<head>
<script type="text/javascript" src="/demo/example/xdom/loadxmldoc.js">
</script>
</head>
<body>
<script type="text/javascript">
xmlDoc=loadXMLDoc("/demo/example/xdom/books.xml");
x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
{
document.write(x.item(i).attributes[0].isId);
document.write("<br />");
}
</script>
</body>
</html>
可以使用本站在线JavaScript测试工具测试上述代码运行效果:http://www.phpcodeweb.com/runjs.html
(IE 浏览器不支持)