我有这个 JavaScript :
<?
var dropzone_maxfiles = '.$product_maxfiles.';
$( ".product_imgfiles" ).click(function(event) {
event.preventDefault();
var img_file = $( this ).children( "img" ).attr( "src" );
$.ajax({
url: "controller/ctrl.dropzonejs-cleaner.php?token='.$product_token.'&key='.$secret_token.'&imgfile="+img_file+""
});
$( this ).parent( "div" ).remove();
dropzone_maxfiles = dropzone_maxfiles + 1;
});
var myDropzone = new Dropzone(".dropzone", {
url: "controller/ctrl.dropzonejs.php?token='.$product_token.'&key='.$secret_token.'",
maxFilesize: 2,
maxFiles: dropzone_maxfiles,
acceptedFiles: ".jpeg, .jpg, .png, .gif"
});
myDropzone.on("complete", function() {
var rejected = myDropzone.getRejectedFiles();
if (rejected == "" ) {
$(".btn-vendor-addnew").removeClass("disabled");
$(".dropzone-error").css("display","none");
}else {
myDropzone.removeAllFiles(true);
$(".btn-vendor-addnew").addClass("disabled");
$(".dropzone-error").css("display","block");
$.ajax({
url: "controller/ctrl.dropzonejs-cleaner.php?token='.$product_token.'&key='.$secret_token.'"
});
}
});
?>
问题是:dropzone_maxfiles = dropzone_maxfiles + 1;
值在maxFiles: dropzone_maxfiles,
中不存在
如何将点击事件中的 dropzone_maxfiles
变量传递到 Dropzone maxFiles
中?谢谢。
最佳答案
就像 @adeneo 在评论中所说,如果变量发生更改,Dropzone
对象的属性 maxFiles
不会自动更改。
相反,尝试使用点击时的当前变量重新初始化它,或者只是更改该属性值(我不确定 Dropzone
是如何实现的,因此可能需要一些 setter 方法来执行这是给你的)。
编辑(根据要求):一个基本示例:
$( ".product_imgfiles" ).click(function(event) {
// ... event handling code
dropzone_maxfiles = dropzone_maxfiles + 1;
// add this to "reset" the Dropzone
myDropzone = new Dropzone(".dropzone", {
url: "controller/ctrl.dropzonejs.php?token='.$product_token.'&key='.$secret_token.'",
maxFilesize: 2,
maxFiles: dropzone_maxfiles,
acceptedFiles: ".jpeg, .jpg, .png, .gif"
});
});
关于javascript - jQuery : Passing Variable Value From On Click Event Failed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36562296/