add() Method ကို ရွေး ပါ။
ဥပမာ
drop-down list ၏အဆုံးတွင် "Kiwi" option ကိုထည့်ပါ။
var x = document.getElementById("mySelect");
var option = document.createElement("option");
option.text = "Kiwi";
x.add(option);
အဓိပ္ပါယ်နှင့် အသုံးပြုမှု
add() method ကို drop-down list တွင် ရွေးစရာတစ်ခုထည့်ရန် အသုံးပြုသည်။
အကြံပြုချက်- drop-down list မှ ရွေးချယ်စရာတစ်ခုကို ဖယ်ရှားရန်၊ remove() နည်းလမ်းကို အသုံးပြုပါ။
Browser ပံ့ပိုးမှု
Method | |||||
---|---|---|---|---|---|
add() | Yes | Yes | Yes | Yes | Yes |
အထားအသို
selectObject.add(option, index)
ကန့်သတ်တန်ဖိုးများ
Parameter | Description |
---|---|
option | Required. Specifies the option to add. Must be an option or optgroup element |
index | Optional. An integer that specifies the index position for where the new option element should be inserted. Index starts at 0. If no index is specified, the new option will be inserted at the end of the list |
နည်းပညာဆိုင်ရာအသေးစိတ်
ပြန်ပို့တန်ဖိုး- | ပြန်တန်ဖိုးမရှိပါ။ |
---|
နောက်ထပ် ဥပမာများ
ဥပမာ
drop-down list ၏အစတွင် "Kiwi" option ကိုထည့်ပါ။
var x = document.getElementById("mySelect");
var option = document.createElement("option");
option.text = "Kiwi";
x.add(option, x[0]);
ဥပမာ
drop-down list ၏ အညွှန်းအနေအထား "2" တွင် "Kiwi" option ကိုထည့်ပါ-
var x = document.getElementById("mySelect");
var option = document.createElement("option");
option.text = "Kiwi";
x.add(option, x[2]);
ဥပမာ
ရွေးချယ်ထားသော ရွေးစရာတစ်ခုရှေ့တွင် ရွေးစရာတစ်ခုကို ဒေါင်းလုပ်ချသည့်စာရင်းတွင် ထည့်ပါ-
var x = document.getElementById("mySelect");
if (x.selectedIndex >= 0) {
var option = document.createElement("option");
option.text = "Kiwi";
var sel = x.options[x.selectedIndex];
x.add(option, sel);
}
❮ Object ကို ရွေးပါ။