Jquery 如何在文件列表中添加文件 请在这方面帮助我:
更新:在控制台日志中,它显示为已合并,但长度仍显示上次拖动的长度 Im使用Jquery 如何在文件列表中添加文件 请在这方面帮助我:,jquery,arrays,html,drag-and-drop,filelist,Jquery,Arrays,Html,Drag And Drop,Filelist,更新:在控制台日志中,它显示为已合并,但长度仍显示上次拖动的长度 Im使用up\u files=event.originalEvent.dataTransfer.files捕获在div中拖放的文件 第一次用户拖动文件时,所有文件都移动到up\u文件,第二次如果文件再次被放入div中,我如何将这些文件推送到现有数组列表,而不是清除数组并插入到upfiles #fileToUpload is a input file id #total is div id 示例代码: $( '#total' ).
up\u files=event.originalEvent.dataTransfer.files
捕获在div中拖放的文件
第一次用户拖动文件时,所有文件都移动到up\u文件
,第二次如果文件再次被放入div中,我如何将这些文件推送到现有数组列表,而不是清除数组并插入到upfiles
#fileToUpload is a input file id
#total is div id
示例代码:
$( '#total' ).bind( 'dragover',function(event) {
event.stopPropagation();
event.preventDefault();
});
$( '#total' ).bind( 'drop',function(event) {
event.stopPropagation();
event.preventDefault();
if( upfiles == 0 )
{
upfiles = event.originalEvent.dataTransfer.files;
upfiles = Array.prototype.slice.call(upfiles, 0);
}
else
{
//push the file here
}
$( "#fileToUpload" ).trigger( 'change' );
});
编辑:
以下是零钱:
$( "#fileToUpload" ).change( function() {
$('#total').css("background-image","");
var fileIn = $( "#fileToUpload" )[0];
if(!upfiles)
{
upfiles = fileIn.files;
upfiles = Array.prototype.slice.call(upfiles, 0);
}
else {
if(fileIn.files.length > 0 ) {
if( confirm( "Drop: Do you want to clear files selected already?" ) == true )
{
upfiles = fileIn.files;
upfiles = Array.prototype.slice.call(upfiles, 0);
}
else
return;
}
//DISPLAYING FILE HERE USING EACH LOOP
} });
更新:
我试过这样做:
$( '#total' ).bind( 'drop',function(event) {
event.stopPropagation();
event.preventDefault();
alert("hello"+upfiles_new);
if( upfiles_new == 0 )
{
upfiles_new = event.originalEvent.dataTransfer.files;
console.dir(upfiles_new);
upfiles = Array.prototype.slice.call(upfiles_new, 0);
}
else {
alert("hello world");
// console.dir(upfiles_new);
upfiles_temp = event.originalEvent.dataTransfer.files;
var upfiles = $.merge(upfiles_temp, upfiles_new)
console.dir(upfiles); // in console log it is merged
upfiles = Array.prototype.slice.call(upfiles, 0); // but in this array it is not showing
alert(print_r(upfiles));
console.dir(upfiles);
}
$( "#fileToUpload" ).trigger( 'change' );
});
我想我更近了。。有人能提出修改意见吗有人能帮我吗