Blob:size 属性
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since January 2020.
备注: 此特性在 Web Worker 中可用。
值
Blob
(或基于 Blob
的对象,例如 File
)所包含数据的字节数。
示例
该实例使用 file
类型的 <input>
元素向用户请求一组文件,然后遍历这些文件,输出它们的名称和大小(以字节为单位)。
HTML
html
<input type="file" id="input" multiple />
<output id="output">选择文件……</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} 文件具有 ${file.size} 字节的大小。\n`;
}
});
规范
Specification |
---|
File API # dfn-size |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
size |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
- Has more compatibility info.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.