jQuery 删除并触发输入类型文件
jQuery drop and trigger input type file
我正在尝试构建自定义拖放和文件上传。我的 div 容器是空的。拖放文件后,我将“一个”类型的文件放入容器中,并希望触发其文件附件功能。我的代码不能正常工作。请提供建议或指导。我们将不胜感激。
以下是我的代码
<div class="drag" ondrop="drop(event)" ondragover="allowDrop(event)">
function allowDrop(event) {
event.preventDefault();
}
function addinputfile(){
$('.drag').append('<div class="upload"><input type="file" name="ufile[]" id="ufile" multiple></div>');
}
function drop(event) {
event.preventDefault();
console.log('something dropped here!');
addinputfile();
$('#input#ufile').trigger("click");
}
代码只是添加“”文件类型并点击它以用于文件上传。
实际上,某些浏览器不允许在输入时触发事件:文件,Click 事件只有在直接来自用户时才会起作用。
但是有其他方法可以做到这一点,请在此处参考 Jquery trigger file input
我正在尝试构建自定义拖放和文件上传。我的 div 容器是空的。拖放文件后,我将“一个”类型的文件放入容器中,并希望触发其文件附件功能。我的代码不能正常工作。请提供建议或指导。我们将不胜感激。
以下是我的代码
<div class="drag" ondrop="drop(event)" ondragover="allowDrop(event)">
function allowDrop(event) {
event.preventDefault();
}
function addinputfile(){
$('.drag').append('<div class="upload"><input type="file" name="ufile[]" id="ufile" multiple></div>');
}
function drop(event) {
event.preventDefault();
console.log('something dropped here!');
addinputfile();
$('#input#ufile').trigger("click");
}
代码只是添加“”文件类型并点击它以用于文件上传。
实际上,某些浏览器不允许在输入时触发事件:文件,Click 事件只有在直接来自用户时才会起作用。
但是有其他方法可以做到这一点,请在此处参考 Jquery trigger file input