วัตถุช่องกาเครื่องหมายอินพุต HTML DOM
อินพุตช่องทำเครื่องหมายวัตถุ
วัตถุช่องทำเครื่องหมายการป้อนข้อมูลแสดงถึงองค์ประกอบ HTML <input> ที่มีประเภท="ช่องทำเครื่องหมาย"
เข้าถึงวัตถุช่องทำเครื่องหมายอินพุต
คุณสามารถเข้าถึงองค์ประกอบ <input> ด้วย type="checkbox" โดยใช้ getElementById():
ตัวอย่าง
var x = document.getElementById("myCheck");
เคล็ดลับ:คุณยังสามารถเข้าถึง <input type="checkbox"> โดยการค้นหาผ่าน คอลเลคชัน องค์ประกอบของฟอร์ม
สร้างวัตถุช่องทำเครื่องหมายอินพุต
คุณสามารถสร้าง <input> องค์ประกอบด้วย type="checkbox" โดยใช้ document.createElement() วิธีการ:
ตัวอย่าง
var x = document.createElement("INPUT");
x.setAttribute("type", "checkbox");
อินพุตช่องทำเครื่องหมายคุณสมบัติของอ็อบเจ็กต์
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 |
คุณสมบัติและเหตุการณ์มาตรฐาน
ออบเจ็กต์ช่องทำเครื่องหมายอินพุตยังสนับสนุนคุณสมบัติและเหตุการณ์ มาตรฐาน อีกด้วย
หน้าที่เกี่ยวข้อง
กวดวิชา HTML: แบบฟอร์ม HTML
อ้างอิง HTML: HTML <input> tag
อ้างอิง HTML: HTML <input> ประเภทแอตทริบิวต์