HTMLSelectElement: phương thức remove()
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.remove() xóa phần tử tại chỉ số được chỉ định khỏi tập hợp tùy chọn của phần tử select này.
Cú pháp
js
remove(index)
Tham số
index-
Một số nguyên bắt đầu từ 0 biểu thị chỉ số của
HTMLOptionElementcần xóa khỏi tập hợp. Nếu không tìm thấy chỉ số, phương thức sẽ không có tác dụng.
Giá trị trả về
Không có (undefined).
Ví dụ
html
<select id="existingList" name="existingList">
<option value="1">Option: Value 1</option>
<option value="2">Option: Value 2</option>
<option value="3">Option: Value 3</option>
</select>
js
let sel = document.getElementById("existingList");
sel.remove(1);
HTML hiện giờ là:
html
<select id="existingList" name="existingList">
<option value="1">Option: Value 1</option>
<option value="3">Option: Value 3</option>
</select>
Đặc tả kỹ thuật
| Specification |
|---|
| HTML> # dom-select-remove> |
Tương thích trình duyệt
Xem thêm
Element.remove, phương thức được gọi khi remove được gọi mà không có đối số trên mộtHTMLSelectElement.HTMLSelectElementtriển khai nó.