我正在使用webkitdirectory来选择一个文件夹。我想获取选择上传的文件夹名称。
答案 0 :(得分:20)
HTML:
<asp:FileUpload ID="FileUpload1" onchange="selectFolder(event)" webkitdirectory mozdirectory msdirectory odirectory directory AllowMultiple="true" runat="server" />
或
<input type="file" id="FileUpload" onchange="selectFolder(event)" webkitdirectory mozdirectory msdirectory odirectory directory multiple />
的javascript:
<script type="text/javascript">
function selectFolder(e) {
var theFiles = e.target.files;
var relativePath = theFiles[0].webkitRelativePath;
var folder = relativePath.split("/");
alert(folder[0]);
}
</script>