जोड़ें () विधि का चयन करें
उदाहरण
ड्रॉप-डाउन सूची के अंत में "कीवी" विकल्प जोड़ें:
var x = document.getElementById("mySelect");
var option = document.createElement("option");
option.text = "Kiwi";
x.add(option);
परिभाषा और उपयोग
ऐड () विधि का उपयोग ड्रॉप-डाउन सूची में एक विकल्प जोड़ने के लिए किया जाता है।
युक्ति: ड्रॉप-डाउन सूची से किसी विकल्प को हटाने के लिए, निकालें () विधि का उपयोग करें।
ब्राउज़र समर्थन
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 |
टेक्निकल डिटेल
प्रतिलाभ की मात्रा: | कोई वापसी मूल्य नहीं |
---|
और ज्यादा उदाहरण
उदाहरण
ड्रॉप-डाउन सूची की शुरुआत में "कीवी" विकल्प जोड़ें:
var x = document.getElementById("mySelect");
var option = document.createElement("option");
option.text = "Kiwi";
x.add(option, x[0]);
उदाहरण
ड्रॉप-डाउन सूची के सूचकांक स्थिति "2" पर "कीवी" विकल्प जोड़ें:
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);
}
वस्तु का चयन करें