Dropzone未定义 [英] Dropzone is not defined
问题描述
我是JavaScript新手,这让我发疯。
I am quite new at JavaScript and this is driving me crazy.
我想使用Dropzone.js所以我从这里并将其包含在我的视图中:
I want to use Dropzone.js so I downloaded the file dropzone.js from here and included it in my view like this:
<script src="<?php echo JS_DIRECTORY; ?>/dropzone.js"></script>
然后我创建了这样的表格:
Then I created the form like that:
<form action="http://localhost/project/uploadTest/upload" class="dropzone">
</form>
它运作正常。它指向php函数,我在服务器站点上处理上传。
And it works fine. It points it to php function and I handle upload on server site.
问题是当我想访问JS中的dropzone对象来配置它时。
当我这样做时
The problem is when I want to access the dropzone object in JS to configure it. When I do
// "myAwesomeDropzone" is the camelized version of the HTML element's ID
Dropzone.options.myAwesomeDropzone = {
paramName: "file", // The name that will be used to transfer the file
maxFilesize: 2, // MB
accept: function(file, done) {
if (file.name == "justinbieber.jpg") {
done("Naha, you don't.");
}
else { done(); }
}
};
我得到
Uncaught ReferenceError:Dropzone未定义
Uncaught ReferenceError: Dropzone is not defined
任何帮助将不胜感激,谢谢
Any help will be appreciated, thanks
推荐答案
您的代码可能运行得太快。包装:
Your code might run too soon. Wrap it in:
window.onload = function() {
// access Dropzone here
};
或更好(比上面的代码早运行):
or, better (runs sooner than above code):
document.addEventListener("DOMContentLoaded", function() {
// access Dropzone here
});
或者,如果你使用 jQuery
:
$(function() {
// access Dropzone here
});
这篇关于Dropzone未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!