我的网络应用程序上有一个拖放区域。拖放区域接受文件夹
<input type="file" multiple="multiple" webkitdirectory mozdirectory />
我可以轻松拖放文件夹、选定的文件夹、单个文件和选定的文件。一切都按预期进行。
当我单击拖放区域时,我会看到标准的 Windows 模式弹出窗口,要求我选择一个文件夹,而不是单个文件。
我想要的是:当我点击拖放区域时,我希望看到正常的 Windows 文件选择模式,而不是文件夹模式
找不到任何解决方案,有可能吗?
最佳答案
这就是 webkitDirectory
的作用,它限制您的 INPUT
仅接受文件夹:
https://wicg.github.io/entries-api/#dom-htmlinputelement-webkitdirectory
The webkitdirectory attribute is a boolean attribute that indicates whether the user is to be allowed to select a directory rather than a file or files.
要支持文件选择以及文件或文件夹的拖放,您需要更改方法,需要一个拖放区域:
https://jsfiddle.net/atfLe15b/
示例来自https://developer.mozilla.org/en-US/docs/Web/API/DataTransferItem/webkitGetAsEntry .
关于javascript - HTML5 文件夹拖放,但单击时选择单个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47674113/