【发布时间】:2016-12-15 18:45:24
【问题描述】:
我有一个用于上传文件的 dropzone 表单,包含在带有 2 个输入文本的标准表单中,提交按钮 (id=submit-all) 的行为由以下 javascript 部分控制(为了上传所有单击按钮后的文件):
Dropzone.options.myDropzone = {
// Prevents Dropzone from uploading dropped files immediately
autoProcessQueue: false,
uploadMultiple: true,
init: function() {
var submitButton = document.querySelector("#submit-all")
myDropzone = this; // closure
submitButton.addEventListener("click", function() {
myDropzone.processQueue(); // Tell Dropzone to process all queued files.
});
this.on("queuecomplete", function (file) {
if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
location.href = 'write.php?final=y';
}
});
}
};
当点击按钮时,所有文件都按预期上传和处理,然后访问者被重定向到页面'write.php?final=y'(恭喜消息)。 但是,当没有选择文件时,此脚本不起作用:单击按钮根本没有效果。
有人可以帮我解决这个问题吗? 非常感谢您的回复!
【问题讨论】:
-
为什么要在 dropzone 中没有文件的情况下使用提交按钮?
-
@Martin:因为提交按钮会触发几件事情:当一些被选中的时候上传和处理图片,但也会发送一封确认邮件,最后重定向到另一个页面。
-
@martin:我忘了说这个表单还包括 2 个输入文本标签