HTML DOM Document Script များ
ဥပမာများ
စာရွက်စာတမ်းရှိ <script> ဒြပ်စင်အရေအတွက်-
document.scripts.length;
ပထမ <script> ဒြပ်စင်၏ အကြောင်းအရာကို ပြန်ပေးသည်-
document.scripts[0].text;
ပထမ <script> ဒြပ်စင်၏ အကြောင်းအရာကို ပြန်ပေးသည်-
document.scripts.item(0).text;
အောက်တွင် နောက်ထပ် ဥပမာများ။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
scripts
ပိုင်ဆိုင်မှုသည် စာရွက်စာတမ်းရှိ <script> ဒြပ်စင်များအားလုံးကို စုစည်းမှုကို ပြန်ပေးသည် ။
scripts
ပိုင်ဆိုင်မှုသည် HTMLCollection တစ်ခုကို ပြန်ပေး သည် ။
scripts
ပိုင်ဆိုင်မှုသည် ဖတ်ရန်သာဖြစ်သည် ။
ကိုလည်းကြည့်ပါ-
Script Object
HTML စုဆောင်းခြင်း။
HTMLCollection သည် HTML node များစုစည်းမှုတစ်ခုဖြစ်သည် ။
စုစည်းမှုတစ်ခုရှိ ဆုံမှတ်များကို အညွှန်းနံပါတ်များဖြင့် ဝင်ရောက်ကြည့်ရှုနိုင်ပါသည်။ အညွှန်းကိန်းသည် 0 တွင် စတင်သည်။
ပိုင်ဆိုင်မှုအရှည် သည် စုစည်းမှုရှိ အစိတ်အပိုင်းအရေအတွက်ကို ပြန်ပေးသည်။
အထားအသို
document.scripts
သတ္တိ
ပစ္စည်းဥစ္စာ | ဖော်ပြချက် |
အရှည် | စုစည်းမှုတွင် <script> အစိတ်အပိုင်းများ အရေအတွက်။ |
နည်းလမ်းများ
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 တစ်ခု။ စာရွက်စာတမ်းရှိ <script> အစိတ်အပိုင်းအားလုံး။ စာရွက်စာတမ်းများတွင် ပေါ်လာသည့်အတိုင်း အစိတ်အပိုင်းများကို စီထားသည်။ |
နောက်ထပ် ဥပမာများ
id="myScript" ဖြင့် <script> ဒြပ်စင်၏ အကြောင်းအရာကို ပြန်ပေးပါ။
document.scripts.namedItem("myScript").text;
<script> ဒြပ်စင်အားလုံးကို လှည့်ပတ်ပြီး id တစ်ခုစီကို ထုတ်ပေးပါ-
const collection = document.scripts;
let text = "";
for (let i = 0; i < collection.length; i++) {
text += collection[i].id + "<br>";
}
Browser ပံ့ပိုးမှု
document.scripts
DOM Level 2 (2001) အင်္ဂါရပ်တစ်ခုဖြစ်သည်။
ဘရောက်ဆာအားလုံးတွင် ၎င်းကို အပြည့်အဝထောက်ခံသည်-
Chrome | IE | Edge | Firefox | Safari | Opera |
Yes | 9-11 | Yes | Yes | Yes | Yes |