值
它表示 Blob(或基於 Blob 的物件,例如 File)中包含的資料位元組數。
示例
此示例使用型別為 file 的 <input> 元素來要求使用者選擇一組檔案,然後遍歷這些檔案並輸出它們的名稱和位元組長度。
HTML
html
<input type="file" id="input" multiple />
<output id="output">Choose files…</output>
JavaScript
js
const input = document.getElementById("input");
const output = document.getElementById("output");
input.addEventListener("change", (event) => {
output.innerText = "";
for (const file of event.target.files) {
output.innerText += `${file.name} has a size of ${file.size} bytes.\n`;
}
});
結果
規範
| 規範 |
|---|
| File API # dfn-size |
瀏覽器相容性
載入中…