substringData()
XML DOM substringData() metodi
❮ Comment obyekti
Misol
Quyidagi kod fragmenti "books_comment.xml" faylini xmlDoc’ga yuklaydi va birinchi izoh elementidan "(Hardcover)" stringini oladi:
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, y, txt, xmlDoc;
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) {
y = x[i].substringData(33, 11);
txt += y + "<br>";
}
}
document.getElementById("demo").innerHTML = txt;
}
Natija:
(Hardcover)
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
substringData() metodi izoh tugunidan string oladi.
Sintaksis
substringData(start,length)| Parametr | Tavsif |
|---|---|
| start | Majburiy. Belgilarni ajratib olish qayerdan boshlanishini belgilaydi. start qiymati noldan boshlanadi |
| length | Majburiy. Nechta belgi ajratib olinishini belgilaydi |
❮ Comment obyekti
W3Schools Pathfinder
Yutuqlaringizni kuzating – bu bepul!
