javascript - 需要我的 JSP 页面上的浏览按钮来选择文件夹(不是文件)
问题描述
这是我想要在我的 JSP 页面上的示例,
我可以浏览文件,但要求是浏览文件夹。
有人可以帮忙吗?
解决方案
HTMLInputElement.webkitdirectory
您可以将属性添加到元素input
。是非标准实现;使用时提供后备。
这是一个片段:
function onFolderChange({ target }) {
const files = target.files;
// file is a FileList, array methods are not supported.
[...files].forEach(console.log); // Needs a recursive function since `file` could be another FileList (a folder)
}
const folderInput = document.getElementById("folderInput");
folderInput.addEventListener('change', onFolderChange);
<label>
Select a folder
<input id="folderInput" type="file" webkitdirectory directory multiple>
</label>
推荐阅读
- sql - 如何将 varchar 显示为百分比,同时使用同一个变量进行别名和链接多个表?
- vegan - 如何用固定的嵌套因子解释 permanova adonis 输出?
- python-3.x - 如何修复关键错误 - 使用 Fousquare API @ Python 中的“组”?
- javascript - 使用 axios 获取文件(内容和文件名)
- php - 提供 x,y,width 和 height 值,我如何获得从中心缩放的 svg 变换矩阵
- python - 获得组内最大的差异
- angularjs - 将编译参数传递给 ng-click 指令
- java - 如何使用 graphql-java 响应扩展?
- c# - 拆分列表框项目并拆分没有选定项目
- mongodb - MongoError:不能在 $in 下嵌套 $