File:name 属性
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 中可用。
值
一个字符串,包含不带路径的文件名,例如“My Resume.rtf”。
示例
HTML
html
<input type="file" id="filepicker" multiple />
<div>
<p>选定文件列表:</p>
<ul id="output"></ul>
</div>
JavaScript
js
const output = document.getElementById("output");
const filepicker = document.getElementById("filepicker");
filepicker.addEventListener("change", (event) => {
const files = event.target.files;
output.textContent = "";
for (const file of files) {
const li = document.createElement("li");
li.textContent = file.name;
output.appendChild(li);
}
});
结果
规范
Specification |
---|
File API # dfn-name |
浏览器兼容性
BCD tables only load in the browser