【发布时间】:2020-03-05 05:11:46
【问题描述】:
我使用js创建表单,我的问题是如何只选择directory,不是 file?
下面是我的代码:
const realFileBtn = document.getElementById("real-file");
const customBtn = document.getElementById("custom-button");
const customTxt = document.getElementById("custom-text");
customBtn.addEventListener("click", function() {
realFileBtn.click();
});
realFileBtn.addEventListener("change", function() {
if (realFileBtn.value) {
customTxt.innerHTML = realFileBtn.value;
} else {
customTxt.innerHTML = "No file chosen, yet.";
}
});
<input type="file" id="real-file" hidden="hidden" />
<button type="button" id="custom-button">CHOOSE A FILE</button>
<span id="custom-text">No file chosen, yet.</span>
下面是我的输出:
实际上我希望输出不要选择file,只需选择 folder,因为下一步我需要将文件存储在此文件夹目录中。
如果成功输出是文件夹目录名称是:
C:\Staff 导入文件夹\Source
希望有人能帮我解决这个问题。谢谢。
【问题讨论】:
标签: javascript html