Đối tượng màu đầu vào HTML DOM
Đối tượng màu đầu vào
Đối tượng Màu đầu vào đại diện cho phần tử HTML <input> có loại = "màu".
Lưu ý: <input type="color"> không được hỗ trợ trong IE 11 và các phiên bản cũ hơn hoặc trong Safari 9.1 và các phiên bản cũ hơn.
Truy cập đối tượng màu đầu vào
Bạn có thể truy cập phần tử <input> bằng type="color" bằng cách sử dụng getElementById():
Mẹo: Bạn cũng có thể truy cập <input type="color"> 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.
Tạo một đối tượng màu đầu vào
Bạn có thể tạo phần tử <input> với type="color" bằng cách sử dụng phương thức document.createElement():
Thuộc tính đối tượng màu đầu vào
Property | Description |
---|---|
autocomplete | Sets or returns the value of the autocomplete attribute of a color picker |
autofocus | Sets or returns whether a color picker should automatically get focus when the page loads |
defaultValue | Sets or returns the default value of a color picker |
disabled | Sets or returns whether a color picker is disabled, or not |
form | Returns a reference to the form that contains the color picker |
list | Returns a reference to the <datalist> element that contains the color picker |
name | Sets or returns the value of the name attribute of a color picker |
type | Returns which type of form element the color picker is |
value | Sets or returns the value of the value attribute of a color picker |
Thuộc tính và sự kiện tiêu chuẩn
Đối tượng Màu đầu vào cũng hỗ trợ các thuộc tính và sự kiện tiêu chuẩn.
Trang liên quan
Hướng dẫn HTML: Biểu mẫu HTML
Tham chiếu HTML: Thẻ HTML <input>
Tham chiếu HTML: Thuộc tính loại HTML <input>