net*_*djw 12 javascript jquery dropzone.js
我正在使用Dropzone.js
上传文件到服务器.我将我的Dropzone maxFiles
参数设置为10,我尝试了这个:
$('.dropzone').dropzone({
maxFiles: 10,
init: function() {
this.on('maxfilesreached', function() {
$('.dropzone').unbind('click');
});
}
});
Run Code Online (Sandbox Code Playgroud)
......但没有工作.从.dropzone或其他任何方式删除可点击以阻止用户添加更多文件的解决方案是什么?
XuD*_*ing 30
为什么不使用CSS来禁用click事件.当达到最大文件时,Dropzone将自动添加一类dz-max-files-reached
.
使用css禁用点击dropzone:
.dz-max-files-reached {
pointer-events: none;
cursor: default;
}
Run Code Online (Sandbox Code Playgroud)
小智 12
这完美地工作!并适用于4.0.1
//disable the click of your clickable area
$(".dz-hidden-input").prop("disabled",true);
//enalbe the click of your clickable area
$(".dz-hidden-input").prop("disabled",false);
Run Code Online (Sandbox Code Playgroud)
小智 6
myDropzone.on('maxfilesreached', function() {
myDropzone.removeEventListeners();
});
myDropzone.on('removedfile', function (file) {
myDropzone.setupEventListeners();
});
Run Code Online (Sandbox Code Playgroud)
如果您的服务器中有文件,请不要忘记init _updateMaxFilesReachedClass.
myDropzone._updateMaxFilesReachedClass()
Run Code Online (Sandbox Code Playgroud)