gpt4 book ai didi

javascript - 当放置区中没有文件时禁用提交按钮

转载 作者:行者123 更新时间:2023-11-29 15:36:48 31 4
gpt4 key购买 nike

我的代码中有一个实现的拖放区,但是我想在我的页面中禁用表单中的提交按钮,当没有文件上传到拖放区时,我有以下代码:

<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 代码,以便根据条件动态禁用/启用提交按钮(无需刷新页面)。在这种情况下,我使用的是放置区,而放置区并不真正支持多个元素,因此我试图以最简单的方式获得解决方法,同时验证所有表单元素。

最佳答案

请检查 HTML 元素 ID 的驼峰版本。 “imageuploaddrop”是真的吗?如果只需要在上传图片时启用提交按钮;你可以尝试设置

autoProcessQueue: true

init: function () {
var submit2 = document.getElementById('submit2');
submit2.disabled = true;
this.on("complete", function (file) {
submit2.disabled = false;
});
}

关于javascript - 当放置区中没有文件时禁用提交按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27480281/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com