我有一个自定义文件输入:
<div id="wrapper">
<span id="fake-text-input"></span>
<button id="select-a-file"></button>
<input id="hidden-file-input" type="file" />
</div>
该 input[type="file"]
隐藏(display: none
并通过监听\触发来处理选择文件 click
和 change
事件。
我也想支持文件丢弃。我能够听到 drop
删除文件时的事件 #fake-text-input
但我不知道如何转发 drop
活动到了 input[type="file"]
..甚至可能吗?
我对文件输入不透明技巧不感兴趣:)
$('body').on('drop', '#wrapper', function(e) {
var file = e.originalEvent.dataTransfer.files[0];
// I have the file.. now what?
});