XML DOM nodeName 属性——Attr 对象

2018-08-05 16:30 更新

XML DOM nodeName 属性


Attr 对象参考手册 Attr 对象

定义和用法

nodeName 属性返回节点的名称,根据其类型。

语法

attrObject.nodeName


实例

下面的代码片段使用 loadXMLDoc() 把 "books.xml" 载入 xmlDoc 中,并显示 category 属性的节点名称、节点值和节点类型:

实例

xmlDoc=loadXMLDoc("books.xml");
x=xmlDoc.getElementsByTagName('book');
for(i=0;i<x.length;i++)
{
document.write(x.item(i).attributes[0].nodeName);
document.write(" = ");
document.write(x.item(i).attributes[0].nodeValue);
document.write(" (nodetype: ");
document.write(x.item(i).attributes[0].nodeType + ")");
document.write("
");
}

输出:

category = COOKING (nodetype: 2)
category = CHILDREN (nodetype: 2)
category = WEB (nodetype: 2)
category = WEB (nodetype: 2)

尝试一下 »

尝试一下 Demos

显示属性的 nodeName、nodeValue 和 nodeType


Attr 对象参考手册 Attr 对象
以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号