使用不带格式的dropzone.options [英] use dropzone.options without form
问题描述
我想在ID上使用dropzone.但是我的Dropzone.options.myid = {}不管用.如何验证文件类型,大小
I want to use dropzone on with id. But my Dropzone.options.myid={} is not working. How to validate file type, size in
var myDropzone = new Dropzone("div#myid", { url: "/file/post"});
我不能使用标签
console.log文件不起作用为什么?我的来源:
console.log file is not working why? My source:
<div id="myid" style="width: 500px; height: 300px; border: 1px solid black">click here</div>
javascript
javascript
var myDropzone = new Dropzone("div#myid",{url:"dropzoneupload"});
var myDropzone = new Dropzone("div#myid", { url: "dropzoneupload"});
Dropzone.options.myid = {
paramName: "file", // The name that will be used to transfer the file
maxFilesize: 2, // MB
accept: function(file, done) {
console.log(file);
if (file.name == "justinbieber.jpg") {
done("Naha, you don't.");
}
else { done(); }
}
};
推荐答案
我看不到您在哪里使用dropzone类定义dropzone区域,它会生成默认的dropzone吗?
I don't see where are you using dropzone class to define your dropzone area, does it generate you the default dropzone?
<div id="myDropZone" class="fallback dropzone" enctype="multipart/form-data">
<input type="file" id="files" class="display" multiple />
</div>
首先,您需要分离默认的放置区,将其添加到文档准备加载中.
First you need to detach the default dropzone, add this out of you document ready load.
Dropzone.autoDiscover = false;
然后用jquery或js
Then you jquery or js
var $myDropZone;
$myDropZone= new Dropzone('div#myDropZone', {*all your settings*
addRemoveLinks: true, //to remove
dictRemoveFile: '<i class="fa fa-times-circle" style="font-weight: 900;
cursor:pointer;"></i>' //I used an icon and styled as button so to give a user
experience to remove it});
希望会有所帮助.
这篇关于使用不带格式的dropzone.options的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!