डेटालिस्ट विकल्प संग्रह
उदाहरण
पता लगाएँ कि एक विशिष्ट <datalist> तत्व में कितने विकल्प हैं:
var x = document.getElementById("browsers").options.length;
एक्स का परिणाम होगा:
5
नीचे और अधिक "इसे स्वयं आज़माएं" उदाहरण।
परिभाषा और उपयोग
विकल्प संग्रह <डेटालिस्ट> तत्व में सभी विकल्पों का संग्रह देता है।
नोट: संग्रह में तत्वों को सॉर्ट किया जाता है जैसे वे स्रोत कोड में दिखाई देते हैं।
ब्राउज़र समर्थन
Collection | |||||
---|---|---|---|---|---|
options | Yes | 10.0 | Yes | Yes | Yes |
वाक्य - विन्यास
datalistObject.options
गुण
Property | Description |
---|---|
length | Returns the number of <option> elements in the collection. Note: This property is read-only |
तरीकों
Method | Description |
---|---|
[index] | Returns the <option> element from the collection with the specified index (starts at 0). Note: Returns null if the index number is out of range |
item(index) | Returns the <option> element from the collection with the specified index (starts at 0). Note: Returns null if the index number is out of range |
namedItem(id) | Returns the <option> element from the collection with the specified id. Note: Returns null if the id does not exist |
टेक्निकल डिटेल
डोम संस्करण: | कोर स्तर 2 दस्तावेज़ वस्तु |
---|---|
प्रतिलाभ की मात्रा: | एक HTMLCollection ऑब्जेक्ट, <datalist> तत्व में सभी <विकल्प> तत्वों का प्रतिनिधित्व करता है। संग्रह में तत्वों को क्रमबद्ध किया जाता है क्योंकि वे स्रोत कोड में दिखाई देते हैं |
और ज्यादा उदाहरण
उदाहरण
[ सूचकांक ]
डेटालिस्ट में पहले विकल्प (इंडेक्स 0) का मान प्राप्त करें:
var x = document.getElementById("browsers").options[0].value;
एक्स का परिणाम होगा:
Internet Explorer
उदाहरण
आइटम ( सूचकांक )
डेटालिस्ट में पहले विकल्प (इंडेक्स 0) का मान प्राप्त करें:
var x = document.getElementById("browsers").options.item(0).value;
एक्स का परिणाम होगा:
Internet Explorer
उदाहरण
नामांकित आइटम ( name_or_id )
एक datalist में id="google" के साथ विकल्प का मूल्य प्राप्त करें:
var x = document.getElementById("browsers").options.namedItem("google").value;
एक्स का परिणाम होगा:
Chrome
उदाहरण
एक डेटालिस्ट में सभी विकल्पों के माध्यम से लूप करें, और विकल्प मानों को आउटपुट करें:
var x = document.getElementById("mySelect");
var txt = "";
var i;
for (i = 0; i < x.options.length; i++) {
txt = txt + x.options[i].value + "<br>";
}
txt का परिणाम होगा:
Internet Explorer
Firefox
Chrome
Opera
Safari
डेटालिस्ट वस्तु