首页 > 解决方案 > 需要我的 JSP 页面上的浏览按钮来选择文件夹(不是文件)

问题描述

这是我想要在我的 JSP 页面上的示例,

在此处输入图像描述

我可以浏览文件,但要求是浏览文件夹。

有人可以帮忙吗?

标签: javascripthtmlcssjsp

解决方案


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>


推荐阅读