Đối tượng hộp kiểm đầu vào HTML DOM
Đối tượng hộp kiểm đầu vào
Đối tượng Hộp kiểm đầu vào đại diện cho phần tử HTML <input> có loại = "hộp kiểm".
Truy cập đối tượng hộp kiểm đầu vào
Bạn có thể truy cập phần tử <input> bằng type="checkbox" bằng cách sử dụng getElementById():
Mẹo: Bạn cũng có thể truy cập <input type="checkbox"> 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 hộp kiểm đầu vào
Bạn có thể tạo phần tử <input> với type="checkbox" bằng cách sử dụng phương thức document.createElement():
Thuộc tính đối tượng hộp kiểm đầu vào
Property | Description |
---|---|
autofocus | Sets or returns whether a checkbox should automatically get focus when the page loads |
checked | Sets or returns the checked state of a checkbox |
defaultChecked | Returns the default value of the checked attribute |
defaultValue | Sets or returns the default value of a checkbox |
disabled | Sets or returns whether a checkbox is disabled, or not |
form | Returns a reference to the form that contains the checkbox |
indeterminate | Sets or returns the indeterminate state of the checkbox |
name | Sets or returns the value of the name attribute of a checkbox |
required | Sets or returns whether the checkbox must be checked before submitting a form |
type | Returns which type of form element the checkbox is |
value | Sets or returns the value of the value attribute of a checkbox |
Thuộc tính và sự kiện tiêu chuẩn
Đối tượng Hộp kiểm đầ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>