Properti nodeValue DOM XML
Definisi dan penggunaan
Properti nodeValue menetapkan atau mengembalikan nilai node berdasarkan tipe node.
Sintaks:
attrObject.nodeValue
contoh
Dalam semua contoh, kita akan menggunakan berkas XML books.xmldan turun JavaScript fungsi loadXMLDoc()。
Kode berikut ini menunjukkan atribut category properti, nama node, nilai node, dan tipe node:
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 />");
}
Output kode di atas:
category = children (nodetype: 2) category = cooking (nodetype: 2) category = web (nodetype: 2) category = web (nodetype: 2)