我尝试在页面中添加Dropzone组件,并且我对此组件感到非常痛苦:无论我做什么,当我点击或删除文件时都没有任何反应dropzone的元素。
<form id="registerUserForm" onsubmit="return submitForm()" class="mt-5">
<div id="dropzoneDiv" class="dropzone dz-clickable">
<div class="dz-default dz-message">
<span>Drop files here to upload</span>
</div>
</div>
.
.
.
</form>
如您所见,我在javascript中配置了Dropzone:
var dropzone=null;
$(document).ready(function () {
Dropzone.autoDiscover = false;
dropzone=$("#dropzoneDiv").dropzone({
url: "/api/works/upload",
acceptedFiles: 'image/*,video/*',
autoProcessQueue: false,
createImageThumbnails: true,
addRemoveLinks: true
});
});
function submitForm() {
dropzone.processQueue();
return false;
}
组件已正确呈现,但是简单不起作用:
我做错了什么我没有注意到?
答案 0 :(得分:0)
我偶然发现了解决方案,问题在于$(document).ready()句子。如果我删除此侦听器并直接使用dropzone配置调用,则该组件可正常工作:
var dropzone = null;
Dropzone.autoDiscover = false;
dropzone = $("#dropzoneDiv").dropzone({
url: "/api/works/upload",
acceptedFiles: 'image/*,video/*',
autoProcessQueue: false,
createImageThumbnails: true,
addRemoveLinks: true
});
function submitForm() {
dropzone.processQueue();
return false;
}
答案 1 :(得分:0)
尝试使用 JQuery 2. *, 如果您使用 JQuery &gt; 3
var dropzone=null;
$(document).ready(function () {
Dropzone.autoDiscover = false;
dropzone=$("#dropzoneDiv").dropzone({
url: "/api/works/upload",
acceptedFiles: 'image/*,video/*',
autoProcessQueue: false,
createImageThumbnails: true,
addRemoveLinks: true
});
});
function submitForm() {
dropzone.processQueue();
return false;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.1.1/min/dropzone.min.css" rel="stylesheet"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.1.1/min/dropzone.min.js"></script>
<form id="registerUserForm" onsubmit="return submitForm()" class="mt-5">
<div id="dropzoneDiv" class="dropzone dz-clickable">
<div class="dz-default dz-message">
<span>Drop files here to upload</span>
</div>
</div>
</form>