วัตถุปุ่มอินพุต HTML DOM
วัตถุปุ่มอินพุต
วัตถุปุ่มป้อนข้อมูลแสดงถึงองค์ประกอบ <input> HTML ที่มีประเภท = "ปุ่ม"
เข้าถึงวัตถุปุ่มอินพุต
คุณสามารถเข้าถึง <input> องค์ประกอบด้วย type="button" โดยใช้ getElementById():
ตัวอย่าง
var x = document.getElementById("myBtn");
เคล็ดลับ:คุณยังสามารถเข้าถึง <input type="button"> โดยการค้นหาผ่าน คอลเลคชัน องค์ประกอบของฟอร์ม
สร้างวัตถุปุ่มอินพุต
คุณสามารถสร้าง <input> องค์ประกอบด้วย type="button" โดยใช้ document.createElement() วิธีการ:
ตัวอย่าง
var x = document.createElement("INPUT");
x.setAttribute("type", "button");
ปุ่มอินพุต คุณสมบัติอ็อบเจ็กต์
Property | Description |
---|---|
autofocus | Sets or returns whether an input button should automatically get focus when the page loads |
defaultValue | Sets or returns the default value of an input button |
disabled | Sets or returns whether an input button is disabled, or not |
form | Returns a reference to the form that contains the input button |
name | Sets or returns the value of the name attribute of an input button |
type | Returns which type of form element the input button is |
value | Sets or returns the value of the value attribute of an input button |
คุณสมบัติและเหตุการณ์มาตรฐาน
ออบเจ็กต์ปุ่มป้อนข้อมูลยังสนับสนุนคุณสมบัติและเหตุการณ์ มาตรฐาน อีกด้วย
หน้าที่เกี่ยวข้อง
กวดวิชา HTML: แบบฟอร์ม HTML
อ้างอิง HTML: HTML <input> tag
อ้างอิง HTML: HTML <input> ประเภทแอตทริบิวต์