[英]Dropzone.js - nothing happens when click dropzone element
I'm trying add Dropzone component in a page and I'm having such a big pain with this component: no matter what I do, nothing happens when I click or drop file in the dropzone's element. 我正在尝试在页面中添加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>
As you can see, I'm configuring Dropzone in javascript: 如您所见,我正在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;
}
The component is correctly rendered, however simple does not work: 组件已正确呈现,但是简单无法正常工作:
Am I doing something wrong I didn't notice? 我做错了什么没注意到吗?
I found the solution by chance, the problem is with $(document).ready() sentence. 我偶然找到了解决方案,问题在于$(document).ready()句子。 If I remove this listener and use the dropzone configuration call directly, the component works correctly: 如果删除此侦听器并直接使用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;
}
Try using JQuery 2.*, If you are using JQuery > 3 尝试使用JQuery 2. *,如果使用的是JQuery > 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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.