appendData()
XML DOM appendData() metodi
❮ Comment obyekti
Misol
Quyidagi kod fragmenti "books_comment.xml" faylini xmlDoc’ga yuklaydi va birinchi izoh elementiga matn qo‘shadi:
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++) {
// Process only comment nodes
if (x[i].nodeType == 8) {
x[i].appendData(" Special Offer");
txt += x[i].data + "<br>";
}
}
document.getElementById("demo").innerHTML = txt;
}
Natija:
125 Simple and Delicious Recipes (Hardcover) Special Offer
O‘zingiz sinab ko‘ring »
Yuqoridagi misolda faqat izoh tugunlarini qayta ishlayotganimizga ishonch hosil qilish uchun sikl va if-tekshiruvdan foydalanamiz. Izoh tugunining tugun turi 8 ga teng.
Ta’rif va qo‘llanilishi
appendData() metodi izoh tugunining oxiriga ma’lumot qo‘shadi.
Sintaksis
commentNode.appedData(string)| Parametr | Tavsif |
|---|---|
| string | Majburiy. Izoh tuguniga qo‘shiladigan string |
❮ Comment obyekti
W3Schools Pathfinder
Yutuqlaringizni kuzating – bu bepul!
