HTMLSelectElement.item()

我们的志愿者还没有将这篇文章翻译为 中文 (简体)加入我们帮助完成翻译
您也可以阅读此文章的English (US)版。

The HTMLSelectElement.item() method returns the Element corresponding to the HTMLOptionElement whose position in the options list corresponds to the index given in parameter, or null if there are none.

In JavaScript, using the array bracket syntax with an unsigned long, like selectElt[idx] is equivalent to selectElt.namedItem(idx).

Syntax

var item = collection.item(idx);
var item = collection[idx];

Parameters

  • idx is an unsigned long.

Return value

Examples

<form>
  <select id="myFormControl" type="textarea">
    <option id="o1">Opt 1</option>
    <option id="o2">Opt 2</option>
  </select>
</form>
elem1 = document.forms[0]["myFormControl"][1]; // Returns the HTMLOptionElement representing #o2

Specifications

Specification Status Comment
HTML Living Standard
The definition of 'HTMLSelectElement.item()' in that specification.
Living Standard No change since the latest snapshot, HTML5.
HTML5
The definition of 'HTMLSelectElement.item()' in that specification.
Recommendation Initial definition, snapshot of HTML Living Standard

Browser compatibility

FeatureChromeEdgeFirefoxInternet ExplorerOperaSafari
Basic support Yes Yes4 Yes Yes ?
FeatureAndroid webviewChrome for AndroidEdge mobileFirefox for AndroidOpera AndroidiOS SafariSamsung Internet
Basic support Yes ? Yes4 Yes ? ?

See also

文档标签和贡献者

此页面的贡献者: connorshea, burnoo, libbymc, fscholz, freaktechnik, teoli
最后编辑者: connorshea,