值
一個數字,表示列表中檔案的數量。
示例
列印所選檔案的數量
在此示例中,我們使用 length 來查詢 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)`;
});
結果
規範
| 規範 |
|---|
| File API # dfn-length |
瀏覽器相容性
載入中…