我需要从Thunderbird程序中拖放多个文件。 它适用于谷歌浏览器,但对于Firefox我只能拖放一个来自雷鸟的电子邮件。 我的代码如下:
<div class="container">
<div class="row">
<div id="result"></div>
<div align="center">
<div id="dock" class="dock">Drag & Drop Emails Here</div>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
// Add eventhandlers for dragover and prevent the default actions for this event
$('#dock').on('dragover', function(e) {
$(this).attr('class', 'dock_hover'); // If drag over the window, we change the class of the #dock div by "dock_hover"
e.preventDefault();
e.stopPropagation();
});
// Add eventhandlers for dragenter and prevent the default actions for this event
$('#dock').on('dragenter', function(e) {
e.preventDefault();
e.stopPropagation();
});
$('#dock').on('dragleave', function(e) {
$(this).attr('class', 'dock'); // If drag OUT the window, we change the class of the #dock div by "dock" (the original one)
});
// When drop the files
$('#dock').on('drop', function(e){ // drop-handler event
if (e.originalEvent.dataTransfer) {
//alert(e.originalEvent.dataTransfer.files.length);
if (e.originalEvent.dataTransfer.files.length) { // Check if we have files
e.preventDefault();
e.stopPropagation();
// Launch the uploads function
upload(e.originalEvent.dataTransfer.files); // Access the dropped files with e.originalEvent.dataTransfer.files
}
}
});
function upload(files){ // uploads function
var fd = new FormData(); // Create a FormData object
//alert("upload");
for (var i = 0; i < files.length; i++) { // Loop all files
fd.append('file_' + i, files[i]); // Create an append() method, one for each file dropped
}
fd.append('nbr_files', i); // The last append is the number of files
$.ajax({ // JQuery Ajax
type: 'POST',
url: sJSUrlImportEmails, // URL to the PHP file which will insert new value in the database
data: fd, // We send the data string
processData: false,
contentType: false,
success: function(data) {
$('#result').html($("#text_import_success").text());
$('#dock').attr('class', 'dock'); // #dock div with the "dock" class
}
});
}
});
</script>
为了保存文件,我使用FormData。 我怎样才能解决我的问题?也许Firefox有一些选择?感谢。