我的代码中有一个已实现的放置区域,但是我想在我的页面中禁用表单中的提交按钮,当没有文件上传到放置区时,我有以下代码:
<script>
// "myAwesomeDropzone" is the camelized version of the HTML element's ID
Dropzone.options.imageuploaddrop = {
paramName: "fileimage",
maxFilesize: 10, // MB
autoProcessQueue: false,
uploadMultiple: false,
maxFiles: 1,
addRemoveLinks: true,
clickable: true,
acceptedFiles: ".jpg,.png,.jpeg,.tif",
dictInvalidFileType: "Invalid File Type. Only Jpg, Png and Tif are supported.",
dictFileTooBig: "File too Big. Maximum 10 MB!",
dictMaxFilesExceeded: "We only need one image.",
init: function () {
this.on("complete", function (file) {
var myDropzone = this;
if (myDropzone.getAcceptedFiles().length = 1) {
myDropzone.processQueue();
} else {
done("There is an Error.");
var submit2 = document.getElementById('submit2');
submit2.disabled = true;
}
});
}
};
</script>
然而,它不起作用。任何人都可以找出原因?谢谢!我在外面尝试了禁用提交代码,看起来检查部分无法正常工作。
实际上,基础是我需要javascript代码,以便根据条件动态禁用/启用提交按钮(无需刷新页面)。在这种情况下,我使用drop zone,drop zone并不真正支持多个元素,因此我尝试以最简单的方式获得解决方法,同时验证所有表单元素。
答案 0 :(得分:1)
请检查HTML元素ID的驼峰版本。 &#34; imageuploaddrop&#34;真的吗? 如果您上传图片时只需要启用提交按钮;你可以尝试设置
autoProcessQueue: true
和
init: function () {
var submit2 = document.getElementById('submit2');
submit2.disabled = true;
this.on("complete", function (file) {
submit2.disabled = false;
});
}