选择文件夹而不是单个文件 - 输入 [英] Select folder instead of single file - input
本文介绍了选择文件夹而不是单个文件 - 输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我希望输入类型是文件夹而不是单个文件.如何选择文件夹而不是单个文件.另外,我如何才能访问所选文件夹中的每个文件.我试过这个来选择一个文件夹,但没有用.我在铬.
I want the input type to be folder and not a single file. How can I select a folder instead of just a single file. Also how can I then access each file in that selected folder. I tried this to select a folder but didn't work. I am on chrome.
<input id="myInput" type="file" style={{visibility: 'hidden'}} webkitdirectory directory multiple/>
推荐答案
您正在寻找 files
属性,它返回一个 filelist.使用 length
获取 files
的数量然后使用 for
语句对所有 files
执行相同的操作,增加每次计数1
You are looking for the files
property, which returns a filelist.
Use length
to get the number of files
then use a for
statement to do the same for all files
, increasing the count by 1 each time
var folder = document.getElementById("myInput");
folder.onchange=function(){
var files = folder.files,
len = files.length,
i;
for(i=0;i<len;i+=1){
console.log(files[i]);
}
}
<input id="myInput" type="file" webkitdirectory directory multiple>
这篇关于选择文件夹而不是单个文件 - 输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文