XML DOM appendData() နည်းလမ်း
❮ မှတ်ချက် 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].appendData(" Special Offer");
txt += x[i].data + "<br>";
}
}
document.getElementById("demo").innerHTML = txt;
}
အထွက်-
125 Simple and Delicious Recipes (Hardcover) Special Offer
အထက်ဖော်ပြပါ ဥပမာတွင် ကျွန်ုပ်တို့သည် မှတ်ချက် node များကိုသာ လုပ်ဆောင်ကြောင်း သေချာစေရန် loop တစ်ခုနှင့် if-test ကို အသုံးပြုပါသည်။ မှတ်ချက် Node တစ်ခုတွင် node အမျိုးအစား 8 ရှိသည်။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
appendData() နည်းလမ်းသည် မှတ်ချက် node တစ်ခု၏အဆုံးတွင် ဒေတာကို ပေါင်းထည့်သည်။
အထားအသို
commentNode.appedData(string)
Parameter | Description |
---|---|
string | Required. The string to add to the comment node |
❮ မှတ်ချက် Object