javascript - HTML5 文件夹拖放,但单击时选择单个文件

标签 javascript jquery html drag-and-drop

我的网络应用程序上有一个拖放区域。拖放区域接受文件夹

<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/

相关文章:

javascript - 为什么 Firefox 不将所有鼠标滚轮事件传递到我的 javascript 应用程序?

javascript - 浏览推文(框)+三个js

php - 在奇数单击和偶数单击链接时创建不同的功能

javascript - Uncaught SyntaxError : Block-scoped declarations (let, const, function, class) 在严格模式之外还不支持

javascript - Highcharts 列 : add dynamically series with drilldown data

php - 代码改进

javascript - 正文加载后运行 jQuery

javascript - 检测用户拖动范围类型输入

跨浏览器范围的 Javascript 插件

javascript - 在 cookie 中保存背景颜色