HTML DOM စာရွက်စာတမ်းလင့်ခ်များ
ဥပမာ
စာရွက်စာတမ်းရှိ လင့်ခ်အရေအတွက်-
let numb = document.links.length;
စာရွက်စာတမ်းရှိ ပထမလင့်ခ်၏ URL ကို ရယူပါ-
let url = document.links[0].href;
စာရွက်စာတမ်းရှိ ပထမလင့်ခ်၏ URL ကို ရယူပါ-
let url = document.links.item(0).href;
အောက်တွင် နောက်ထပ် ဥပမာများ။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
links
ပိုင်ဆိုင်မှုသည် စာရွက်စာတမ်းရှိ လင့်ခ်များ စုစည်းမှုအားလုံးကို ပြန်ပေးသည် ။
forms
ပိုင်ဆိုင်မှုသည် HTMLCollection တစ်ခုကို ပြန်ပေး သည် ။
links
ပိုင်ဆိုင်မှုသည် ဖတ်ရန်သာဖြစ်သည် ။
စုစည်းမှုရှိလင့်ခ်များသည် href attribute ဖြင့် <a> နှင့် <area> ဒြပ်စင်များကို ကိုယ်စားပြုသည်။
ကိုလည်းကြည့်ပါ-
HTML စုဆောင်းခြင်း။
HTMLCollection သည် HTML node များစုစည်းမှုတစ်ခုဖြစ်သည် ။
စုစည်းမှုတစ်ခုရှိ ဆုံမှတ်များကို အညွှန်းနံပါတ်များဖြင့် ဝင်ရောက်ကြည့်ရှုနိုင်ပါသည်။ အညွှန်းကိန်းသည် 0 တွင် စတင်သည်။
ပိုင်ဆိုင်မှုအရှည် သည် စုစည်းမှုရှိ အစိတ်အပိုင်းအရေအတွက်ကို ပြန်ပေးသည်။
အထားအသို
document.links
သတ္တိ
Property | Description |
length | The number of elements in the collection. |
နည်းလမ်းများ
Method | Description |
[index] | Returns the element with the specified index (starts at 0). Returns null if the index is out of range. |
item(index) | Returns the element with the specified index (starts at 0). Returns null if the index is out of range. |
namedItem(id) | Returns the element with the specified id. Returns null if the id does not exist. |
တန်ဖိုးကို ပြန်ပေးသည်။
ရိုက်ပါ။ | ဖော်ပြချက် |
အရာဝတ္ထု | HTMLCollection Object တစ်ခု ။ စာရွက်စာတမ်းရှိ <a> နှင့် <area> အစိတ်အပိုင်းများအားလုံး။ စာရွက်စာတမ်းများတွင် ပေါ်လာသည့်အတိုင်း အစိတ်အပိုင်းများကို စီထားသည်။ |
နောက်ထပ် ဥပမာများ
id="myLink" ဖြင့် ဒြပ်စင်၏ URL ကို ရယူပါ-
let url = document.links.namedItem("myLink").href;
စာရွက်စာတမ်းရှိ ပထမဆုံးလင့်ခ်သို့ အနီရောင်ဘောင်တစ်ခု ထည့်ပါ-
document.links[0].style.border = "5px solid red";
လင့်အားလုံးကို လှည့်ပတ်ပြီး တစ်ခုစီ၏ URL (href) ကို ထုတ်ပေးသည်-
const links = document.links;
let text = "";
for (let i = 0; i < links.length; i++) {
text += links[i].href + "<br>";
}
Browser ပံ့ပိုးမှု
document.links
DOM Level 1 (1998) အင်္ဂါရပ်တစ်ခုဖြစ်သည်။
ဘရောက်ဆာအားလုံးတွင် ၎င်းကို အပြည့်အဝထောက်ခံသည်-
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |