XML DOM nodeValue 屬性
定義和用法
nodeValue
屬性設置或返回節點的值,根據其類型。
語法
documentObject.nodeValue
實例
下面的代碼將 "books.xml" 加載到 xmlDoc 中,并顯示根節點的節點名稱和節點值:
var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { myFunction(this); } }; xhttp.open("GET", "books.xml", true); xhttp.send(); function myFunction(xml) { var xmlDoc = xml.responseXML; document.getElementById("demo").innerHTML = "Nodename: " + xmlDoc.nodeName + (" (value: " + xmlDoc.childNodes[0].nodeValue) + ")"; }