XML DOM appendData() 方法
ການອະທິບາຍ ແລະ ການນໍາໃຊ້
appendData()
ກົນລະບົບ ແລະ ການນໍາໃຊ້ XML DOM appendData()
ວິທິພາສາ
commentNode.appedData(string)
ປະເພາະ | ການອະທິບາຍ |
---|---|
string | ຄວາມຕ້ອງການ |
ຄວາມນິຍົມ
ລະຫັດກ່າວດັ່ງກ່າວນີ້ ຈະ "books_comment.xml" ບັນທຶກໃນ xmlDoc ແລະ ສິນລະບາຍຄວາມຂັບເຂົ້າໃນຫົວຂໍ້ຄຳຄິດທໍາອິດ:
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++) { // ຈະເຂົ້າໃຊ້ການດຳເນີນກັບຫົວຂໍ້ຄຳຄິດດຽວເທົ່ານັ້ນ if (x[i].nodeType == 8) { x[i].appendData("ຂໍ້ສະເໜີພິເສດ"); txt += x[i].data + "<br>"; } } document.getElementById("demo").innerHTML = txt; }
在上面的例子中,我们用了循环和 if 测试语句,来确保我们只处理注释节点。注释节点的节点类型为 8。