HTMLSelectElement: phương thức item()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Phương thức HTMLSelectElement.item() trả về Element tương ứng với HTMLOptionElement có vị trí trong danh sách tùy chọn khớp với chỉ số được truyền vào tham số, hoặc null nếu không có phần tử nào.
Trong JavaScript, dùng cú pháp ngoặc vuông với một unsigned long, như selectElt[index], tương đương với selectElt.namedItem(index).
Cú pháp
js
item(index)
// or collection[index]
Tham số
index-
Một số nguyên không âm biểu thị vị trí của option trong danh sách.
Giá trị trả về
Một HTMLOptionElement hoặc null.
Ví dụ
>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];
Đặc tả kỹ thuật
| Specification |
|---|
| HTML> # dom-select-item-dev> |
Tương thích trình duyệt
Xem thêm
HTMLSelectElementtriển khai nó.