HTML <input> ยอมรับแอตทริบิวต์
ตัวอย่าง
ระบุประเภทไฟล์ที่ผู้ใช้สามารถเลือกได้จากกล่องโต้ตอบการป้อนไฟล์:
<form action="/action_page.php">
<label for="img">Select image:</label>
<input type="file" id="img"
name="img" accept="image/*">
<input type="submit">
</form>
ความหมายและการใช้งาน
แอตทริบิวต์accept
ระบุตัวกรองสำหรับประเภทไฟล์ที่ผู้ใช้สามารถเลือกได้จากกล่องโต้ตอบการป้อนไฟล์
หมายเหตุ:แอตทริบิวต์accept
สามารถใช้ได้กับ
<input type="file">
.
เคล็ดลับ:อย่าใช้แอตทริบิวต์นี้เป็นเครื่องมือตรวจสอบ การอัปโหลดไฟล์ควรตรวจสอบความถูกต้องบนเซิร์ฟเวอร์
รองรับเบราว์เซอร์
ตัวเลขในตารางระบุเบราว์เซอร์รุ่นแรกที่สนับสนุนแอตทริบิวต์อย่างเต็มที่
Attribute | |||||
---|---|---|---|---|---|
accept | 26.0 | 10.0 | 37.0 | 11.1 | 15.0 |
ไวยากรณ์
<input accept="file_extension|audio/*|video/*|image/*|media_type">
เคล็ดลับ:หากต้องการระบุมากกว่าหนึ่งค่า ให้คั่นค่าด้วยเครื่องหมายจุลภาค (เช่น<input accept="audio/*,video/*,image/*" />
.
ค่าแอตทริบิวต์
Value | Description |
---|---|
file_extension | Specify the file extension(s) (e.g: .gif, .jpg, .png, .doc) the user can pick from |
audio/* | The user can pick all sound files |
video/* | The user can pick all video files |
image/* | The user can pick all image files |
media_type | A valid media type, with no parameters. Look at IANA Media Types for a complete list of standard media types |
❮ แท็ก HTML <input>