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