Đối tượng tải lên tệp đầu vào HTML DOM
Đối tượng tải lên tệp đầu vào
Đối tượng FileUpload đầu vào đại diện cho một phần tử HTML <input> có type="file".
Truy cập đối tượng tải lên tệp đầu vào
Bạn có thể truy cập phần tử <input> bằng type="file" bằng cách sử dụng getElementById():
Mẹo: Bạn cũng có thể truy cập <input type="file"> bằng cách tìm kiếm thông qua bộ sưu tập thành phần của biểu mẫu.
Tạo một đối tượng tải lên tệp đầu vào
Bạn có thể tạo phần tử <input> với type="file" bằng cách sử dụng phương thức document.createElement():
Nhập thuộc tính đối tượng 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 |
Thuộc tính và sự kiện tiêu chuẩn
Đối tượng FileUpload đầu vào cũng hỗ trợ các thuộc tính và sự kiện tiêu chuẩn.
Trang liên quan
Hướng dẫn HTML: Biểu mẫu HTML
Tham chiếu HTML: Thẻ HTML <input>
Tham chiếu HTML: Thuộc tính loại HTML <input>