FileList: length property
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
Note: This feature is available in Web Workers.
Thuộc tính chỉ đọc length của giao diện FileList trả về số lượng tệp trong FileList.
Giá trị
Một số cho biết số lượng tệp trong danh sách.
Ví dụ
>In số lượng tệp được chọn
Trong ví dụ này, chúng ta sử dụng length để tìm số mục trong FileList.
HTML
html
<input type="file" multiple />
<div class="output"></div>
JavaScript
js
const fileInput = document.querySelector("input[type=file]");
const output = document.querySelector(".output");
fileInput.addEventListener("change", () => {
const fileList = fileInput.files;
output.textContent = `You've selected: ${fileList.length} file(s)`;
});
Kết quả
Thông số kỹ thuật
| Thông số kỹ thuật |
|---|
| File API> # dfn-length> |