Thuộc tính DOM nodeValue trong XML
❮ Đối tượng nút
Thí dụ
Đoạn mã sau tải " books.xml " vào xmlDoc và hiển thị tên nút và giá trị nút của nút gốc:
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) +
")";
}
Đầu ra của đoạn mã trên sẽ là:
Nodename: #document (value: null)
Định nghĩa và Cách sử dụng
Thuộc tính nodeValue đặt hoặc trả về giá trị của một nút, tùy thuộc vào kiểu của nó.
Cú pháp
nodeObject.nodeValue
❮ Đối tượng nút