HTML DOM hasAttribute() နည်းလမ်း
❮ Element Objectဥပမာ
<button> ဒြပ်စင်တစ်ခုတွင် onclick ရည်ညွှန်းချက်ရှိမရှိ ရှာဖွေပါ-
var x = document.getElementById("myBtn").hasAttribute("onclick");
အောက်တွင် နောက်ထပ် "စမ်းသုံးကြည့်ပါ" ဥပမာများ။
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
သတ်မှတ်ထားသော attribute ရှိလျှင် hasAttribute() method သည် true ပြန်ပေးသည်၊ သို့မဟုတ်ပါက ၎င်းသည် false ပြန်ပေးသည်။
အကြံပြုချက်- ရည်ညွှန်းချက်အသစ်တစ်ခု ထည့်ရန် သို့မဟုတ် ဒြပ်စင်တစ်ခုပေါ်ရှိ ရှိပြီးသား attribute ၏တန်ဖိုးကို ပြောင်းလဲရန် setAttribute() ကို အသုံးပြု ပါ။
Browser ပံ့ပိုးမှု
ဇယားရှိ နံပါတ်များသည် နည်းလမ်းကို အပြည့်အဝထောက်ခံသည့် ပထမဆုံးဘရောက်ဆာဗားရှင်းကို သတ်မှတ်ပေးသည်။
Method | |||||
---|---|---|---|---|---|
hasAttribute() | Yes | 9.0 | Yes | Yes | Yes |
အထားအသို
element.hasAttribute(attributename)
ကန့်သတ်ချက်များ
Parameter | Type | Description |
---|---|---|
attributename | String | Required. The name of the attribute you want to check if exists |
နည်းပညာဆိုင်ရာအသေးစိတ်
ပြန်ပို့တန်ဖိုး- | Boolean သည် ဒြပ်စင်တွင် attribute များရှိပါက မဟုတ်လျှင် false သည် true ပြန်ပေးသည်။ |
---|---|
DOM ဗားရှင်း | Core Level 2 Element Object |
နောက်ထပ် ဥပမာများ
ဥပမာ
<a> ဒြပ်စင်တစ်ခုတွင် ပစ်မှတ်ရည်ညွှန်းချက်ရှိမရှိ ရှာဖွေပါ။ သို့ဆိုလျှင်၊ ပစ်မှတ်ရည်ညွှန်းချက်၏တန်ဖိုးကို "_self" သို့ပြောင်းပါ-
// Get the <a> element with id="myAnchor"
var x = document.getElementById("myAnchor");
// If the <a> element has a target attribute, set the value to "_self"
if (x.hasAttribute("target")) {
x.setAttribute("target", "_self");
}
ဆက်စပ်စာမျက်နှာများ
HTML သင်ခန်းစာ- HTML အရည်အချင်းများ
HTML DOM အကိုးအကား- getAttribute() နည်းလမ်း
HTML DOM အကိုးအကား- removeAttribute() နည်းလမ်း
HTML DOM ရည်ညွှန်းချက်- setAttribute() နည်းလမ်း
❮ Element Object