XML DOM nodeValue 屬性

定義和用法

nodeValue 屬性根據節點的類型設置或返回節點的值。

語法:

attrObject.nodeValue

實例

在所有的例子中,我們將使用 XML 文件 books.xml,以及 JavaScript 函數 loadXMLDoc()

下面的代碼片段顯示 category 屬性的節點名稱、節點值以及節點類型:

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].nodeName);
document.write(" = ");
document.write(x.item(i).attributes[0].nodeValue);
document.write(" (nodetype: ");
document.write(x.item(i).attributes[0].nodeType + ")");
document.write("<br />");
}

以上代碼的輸出:

category = children (nodetype: 2)
category = cooking (nodetype: 2)
category = web (nodetype: 2)
category = web (nodetype: 2)