Dropzone.js - 单击 dropzone 元素时没有任何反应

Dropzone.js - nothing happens when click dropzone 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>

如您所见,我正在 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;
}     

组件已正确呈现,但简单不起作用:

我是不是做错了什么我没有注意到?

我偶然找到了解决方案,问题出在 $(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;
}

尝试使用 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>