XML DOM nodeValue 屬性


Attr 對象參考手冊 Attr 對象

定義和用法

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

語法

attrObject.nodeValue


實例

下麵的代碼片段使用 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: " + x.item(i).attributes[0].nodeType + ")"); document.write("<br>"); }

輸出:

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


Attr 對象參考手冊 Attr 對象