XML DOM length attribute
Definition and Usage
length
Ibinabalik ng attribute na ito ang haba ng teksto ng pahina ng komento (sa bilang ng character).
Attribute
commentNode.length
Sample
Ang kodigo sa ibaba ay maglalaad ng "books_comment.xml" sa xmlDoc, at magkakuha ng datos ng text node at haba mula sa unang <title> elemento:
var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { myFunction(this); } }; xhttp.open("GET", "books_comment.xml", true); xhttp.send(); function myFunction(xml) { var x, i, xmlDoc, txt; xmlDoc = xml.responseXML; txt = ""; x = xmlDoc.getElementsByTagName("book")[0].childNodes; for (i = 0; i < x.length; i++) { // Ayusapin ng kodigo lamang ang mga pahina ng komento if (x[i].nodeType == 8) { txt += x[i].length + "<br>"; } } document.getElementById("demo").innerHTML = txt; }
在上面的例子中,我們用了循環和 if 測試語句,來確保我們只處理注釋節點。注釋節點的節點類型為 8。