Đối tượng hộp kiểm đầu vào HTML DOM
Nhập đối tượng hộp kiểm
Đối tượng Hộp kiểm đầu vào đại diện cho một phần tử HTML <input> với type = "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> với type = "checkbox" bằng cách sử dụng getElementById ():
Thí dụ
var x = document.getElementById("myCheck");
Mẹo: Bạn cũng có thể truy cập <input type = "checkbox"> 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 đố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 ():
Thí dụ
var x = document.createElement("INPUT");
x.setAttribute("type", "checkbox");
Nhập thuộc tính đối tượng hộp kiểm
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 .
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>