HTMLSelectElement: item() Methode
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since Juli 2015.
Die HTMLSelectElement.item()
Methode gibt das Element
zurück, das dem HTMLOptionElement
entspricht, dessen Position in der Optionsliste dem im Parameter angegebenen Index entspricht, oder null
, falls keine vorhanden sind.
Im JavaScript ist die Verwendung der Array-Klammer-Syntax mit einem unsigned long
, wie selectElt[index]
, gleichbedeutend mit selectElt.namedItem(index)
.
Syntax
js
item(index)
// or collection[index]
Parameter
index
-
Eine nicht negative Ganzzahl, die die Position der Option in der Liste darstellt.
Rückgabewert
Ein HTMLOptionElement
oder null
.
Beispiele
>HTML
html
<form>
<select id="myFormControl">
<option id="o1">Opt 1</option>
<option id="o2">Opt 2</option>
</select>
</form>
JavaScript
js
// Returns the HTMLOptionElement representing #o2
elem1 = document.forms[0]["myFormControl"][1];
Spezifikationen
Specification |
---|
HTML> # dom-select-item-dev> |
Browser-Kompatibilität
Loading…
Siehe auch
HTMLSelectElement
, das es implementiert.