Đối tượng tùy chọn HTML DOM
Đối tượng tùy chọn
Đối tượng Option đại diện cho một phần tử HTML <option>.
Truy cập một đối tượng tùy chọn
Bạn có thể truy cập một phần tử <option> bằng cách sử dụng getElementById ():
Thí dụ
var x = document.getElementById("myOption");
Mẹo: Bạn cũng có thể truy cập một đối tượng Tùy chọn bằng cách tìm kiếm qua bộ sưu tập phần tử 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 một phần tử <option> bằng cách sử dụng phương thức document.createElement ():
Thí dụ
var x = document.createElement("OPTION");
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 .
Các trang liên quan
Tham chiếu HTML: thẻ HTML <option>