Đố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 một phần tử HTML <input> với type = "color".
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 một đối tượng màu đầu vào
Bạn có thể truy cập phần tử <input> với type = "color" bằng cách sử dụng getElementById ():
Thí dụ
var x = document.getElementById("myColor");
Mẹo: Bạn cũng có thể truy cập <input type = "color"> bằng cách tìm kiếm qua bộ sưu tập phần tử của một 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 ():
Thí dụ
var x = document.createElement("INPUT");
x.setAttribute("type", "color");
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 .
Các 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>