XML DOM nodeName 屬性
Attr 對象
定義和用法
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 對象