[英]Dropzone is not defined
我是JavaScript的新手,这让我发疯。
我想使用Dropzone.js,所以我从这里下载了文件dropzone.js并将其包含在我的视图中,如下所示:
<script src="<?php echo JS_DIRECTORY; ?>/dropzone.js"></script>
然后我创建了这样的表单:
<form action="http://localhost/project/uploadTest/upload" class="dropzone">
</form>
它工作正常。 它指向php功能,我处理服务器站点上传。
问题是当我想访问JS中的dropzone对象来配置它时。 当我做
// "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(); }
}
};
我明白了
未捕获的ReferenceError:未定义Dropzone
任何帮助将不胜感激,谢谢
您的代码可能运行得太快。 包裹它:
window.onload = function() {
// access Dropzone here
};
或者,更好(比上面的代码早运行):
document.addEventListener("DOMContentLoaded", function() {
// access Dropzone here
});
或者,如果你使用jQuery
:
$(function() {
// access Dropzone here
});
按照这个:
你的HTML文件:
<form action="your url" class="dropzone" id="dropzone-form">
</form>
你的JS档案:
window.onload = function() {
// dropzoneFormis the configuration for the element that has an id attribute
// with the value dropzone-form (or dropzoneForm)
//initialize the dropzone;
Dropzone.options.dropzoneForm = {
autoProcessQueue: 'your value',
acceptedFiles: 'your value',
maxFilesize: 'your value',
....and so on.
init: function() {
myDropzone = this;
this.on('addedfile', function(file) {
//todo...something...
}
//catch other events here...
}
};
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.