HTML DOM ရည်ညွှန်းချက်များ အကြောင်းအရာ()
ဥပမာ
ဒြပ်စင်တစ်ခု၏ ပထမဂုဏ်ရည်တော်များ၏ အမည်ကို ရယူပါ-
const nodeMap = document.getElementById("myDiv").attributes;
let name1 = nodeMap.item(0).name;
let name2 = nodeMap.item(1).name;
const nodeMap = document.getElementById("myDiv").attributes;
let name1 = nodeMap[0].name;
let name2 = nodeMap[1].name;
အောက်တွင် နောက်ထပ် ဥပမာများ။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
နည်းလမ်း သည် item()
NamedNodeMap မှ attribute တစ်ခု (အညွှန်းအားဖြင့်) ပြန်ပေးသည်။
မှတ်ချက်
ရင်းမြစ်ကုဒ်တွင် ပေါ်လာသည့်အတိုင်း ဆုံမှတ်များကို စီထားသည်။ အညွှန်းကိန်းသည် 0 တွင် စတင်သည်။
ကိုလည်းကြည့်ပါ-
အထားအသို
namednodemap.item(index)
or simply:
namednodemap[index]
ကန့်သတ်ချက်များ
Parameter | Description |
index | Required. The index of the attribute node in the NamedNodeMap. |
တန်ဖိုးကို ပြန်ပေးသည်။
ရိုက်ပါ။ | ဖော်ပြချက် |
node တစ်ခု | သတ်မှတ်ထားသော အညွှန်းတွင် attribute node သို့မဟုတ် null အညွှန်းကိန်းနံပါတ်သည် အပိုင်းအခြားမဟုတ်ပါက၊ |
နောက်ထပ် ဥပမာများ
ဒြပ်စင်တစ်ခု၏ အတန်းအစား (အရောင်) ကို ပြောင်းပါ-
document.getElementById("myDiv").attributes.item(1).value = "class2";
ဒြပ်စင်တစ်ခု၏ အတန်းအစား (အရောင်) ကို ပြောင်းပါ-
document.getElementById("myDiv").attributes[1].value = "class2";
Browser ပံ့ပိုးမှု
attributes.item()
DOM Level 1 (1998) အင်္ဂါရပ်တစ်ခုဖြစ်သည်။
ဘရောက်ဆာအားလုံးတွင် ၎င်းကို အပြည့်အဝထောက်ခံသည်-
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |