ออบเจ็กต์การอัปโหลดไฟล์ HTML DOM
อินพุต FileUpload Object
วัตถุ Input FileUpload แสดงถึงองค์ประกอบ HTML <input> ที่มีประเภท = "ไฟล์"
เข้าถึงอินพุต FileUpload Object
คุณสามารถเข้าถึง <input> องค์ประกอบด้วย type="file" โดยใช้ getElementById():
ตัวอย่าง
var x = document.getElementById("myFile");
เคล็ดลับ:คุณยังสามารถเข้าถึง <input type="file"> โดยการค้นหาผ่าน คอลเลคชัน องค์ประกอบของฟอร์ม
สร้างอินพุต FileUpload Object
คุณสามารถสร้าง <input> องค์ประกอบด้วย type="file" โดยใช้ document.createElement() วิธีการ:
ตัวอย่าง
var x = document.createElement("INPUT");
x.setAttribute("type", "file");
อินพุต FileUpload คุณสมบัติอ็อบเจ็กต์
Property | Description |
---|---|
accept | Sets or returns the value of the accept attribute of the file upload button |
autofocus | Sets or returns whether a file upload button should automatically get focus upon page load |
defaultValue | Sets or returns the default value of the file upload button |
disabled | Sets or returns whether the file upload button is disabled, or not |
files | Returns a FileList object that represents the file or files selected with the file upload button |
form | Returns a reference to the form that contains the file upload button |
multiple | Sets or returns whether a user is allowed to select more than one file in the file upload field |
name | Sets or returns the value of the name attribute of the file upload button |
required | Sets or returns whether a file in the file upload field must be selected before submitting a form |
type | Returns which type of form element the file upload button is |
value | Returns the path or the name of the selected file |
คุณสมบัติและเหตุการณ์มาตรฐาน
ออบเจ็กต์ Input FileUpload ยังสนับสนุนคุณสมบัติและเหตุการณ์ มาตรฐาน อีกด้วย
หน้าที่เกี่ยวข้อง
กวดวิชา HTML: แบบฟอร์ม HTML
อ้างอิง HTML: HTML <input> tag
อ้างอิง HTML: HTML <input> ประเภทแอตทริบิวต์