XML DOM item() နည်းလမ်း
❮ NodeList Object
ဥပမာ
မှတ်ချက်- Internet Explorer မှလွဲ၍ အဓိကဘရောက်ဆာများအားလုံးသည် အလွတ်အဖြူကွက်များ သို့မဟုတ် လိုင်းအသစ်များကို စာသား nodeများအဖြစ် ဆက်ဆံပါသည်။ ထို့ကြောင့်၊ အောက်ပါဥပမာတွင်၊ node အမျိုးအစားကိုစစ်ဆေးပြီး Element node များကိုသာပြသသည့်လုပ်ဆောင်ချက်တစ်ခုရှိသည်။ ဤနည်းအားဖြင့်၊ ရလဒ်သည် browser အားလုံးတွင်တူညီလိမ့်မည်။ ဘရောက်ဆာများကြား ခြားနားချက်များကို ပိုမိုဖတ်ရှုရန်၊ ကျွန်ုပ်တို့၏ DOM ဘရောက်ဆာများ အခန်းကို ဖတ်ရှုပါ။
အောက်ပါ ကုဒ်အပိုင်းအစသည် " books.xml " ကို xmlDoc ထဲသို့ တင်ပြီး <bookstore> ဒြပ်စင်၏ ကလေးဒြပ်စင် များအားလုံးကို လှည့်ပတ်သည်-
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myFunction(this);
}
};
xhttp.open("GET", "books.xml", true);
xhttp.send();
function myFunction(xml) {
var x, i, xmlDoc, txt;
xmlDoc = xml.responseXML;
txt = "";
x = xmlDoc.documentElement.childNodes;
for (i = 0; i <
x.length; i++) {
if (x.item(i).nodeType
== 1) {
txt += x.item(i).nodeName + "<br>";
}
}
document.getElementById("demo").innerHTML
= txt;
}
အထွက်-
book
book
book
book
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
item() method သည် node စာရင်းရှိ သတ်မှတ်ထားသော အညွှန်းတွင် node ကို ပြန်ပေးသည်။
မှတ်ချက်- node စာရင်းရှိ အရာများကို 0 မှစတင်၍ အညွှန်းတစ်ခုမှတစ်ဆင့် ဝင်ရောက်ကြည့်ရှုနိုင်ပါသည်။
Browser ပံ့ပိုးမှု
item() နည်းလမ်းကို အဓိက ဘရောက်ဆာအားလုံးတွင် ပံ့ပိုးထားသည်။
အထားအသို
nodelist.item(index)
ကန့်သတ်ချက်များ
Parameter | Type | Description |
---|---|---|
index | Number | Required. The index of the node in the node list. The index starts at 0 |
တန်ဖိုးကို ပြန်ပေးသည်။
Type | Description |
---|---|
Node object | The node at the specified index, or null if the index is out of rangex |
နည်းပညာဆိုင်ရာအသေးစိတ်
DOM ဗားရှင်း | Core Level 1 Nodelist Object |
---|
❮ NodeList Object