XML DOM insertData() နည်းလမ်း
❮ မှတ်ချက် Object
ဥပမာ
အောက်ဖော်ပြပါ ကုဒ်အပိုင်းအစသည် " 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++) {
// Process only
comment nodes
if (x[i].nodeType
== 8) {
x[i].insertData(25, "Italian ");
txt += x[i].data + "<br>";
}
}
document.getElementById("demo").innerHTML = txt;
}
အထွက်-
125 Simple and Delicious Italian Recipes (Hardcover)
အထက်ဖော်ပြပါ ဥပမာတွင် ကျွန်ုပ်တို့သည် မှတ်ချက် node များကိုသာ လုပ်ဆောင်ကြောင်း သေချာစေရန် loop တစ်ခုနှင့် if-test ကို အသုံးပြုပါသည်။ မှတ်ချက် Node တစ်ခုတွင် node အမျိုးအစား 8 ရှိသည်။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
insertData() method သည် comment node တွင် data များကို ထည့်သွင်းသည်။
အထားအသို
commentNode.insertData(start,string)
Parameter | Description |
---|---|
start | Required. Specifies where to begin inserting characters. Start value starts at zero |
string | Required. Specifies the string to insert |
❮ မှတ်ချက် Object