Đối tượng tùy chọn HTML DOM
Đối tượng tùy chọn
Đối tượng Option đại diện cho phần tử HTML <option>.
Truy cập một đối tượng tùy chọn
Bạn có thể truy cập phần tử <option> bằng cách sử dụng getElementById():
Mẹo: Bạn cũng có thể truy cập đối tượng Tùy chọn bằng cách tìm kiếm thông qua bộ sưu tập thành phần của biểu mẫu hoặc bộ sưu tập tùy chọn của danh sách thả xuống.
Tạo một đối tượng tùy chọn
Bạn có thể tạo phần tử <option> bằng cách sử dụng phương thức document.createElement():
Thuộc tính đối tượng tùy chọn
Property | Description |
---|---|
defaultSelected | Returns the default value of the selected attribute |
disabled | Sets or returns whether an option is disabled, or not |
form | Returns a reference to the form that contains the option |
index | Sets or returns the index position of an option in a drop-down list |
label | Sets or returns the value of the label attribute of an option in a drop-down list |
selected | Sets or returns the selected state of an option |
text | Sets or returns the text of an option |
value | Sets or returns the value of an option to be sent to the server |
Thuộc tính và sự kiện tiêu chuẩn
Đối tượng Option cũng hỗ trợ các thuộc tính và sự kiện tiêu chuẩn.
Trang liên quan
Tham chiếu HTML: thẻ HTML <option>