javascript Dropzone.js init function() 未被调用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22169595/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Dropzone.js init function() not being called
提问by Todd
I have this HTML:
我有这个 HTML:
<div id='drop_zone'>
<div class="close_button" id="removeAllImages">Remove All</div>
<form action="PHP/uploads.php" class="dropzone" id='fbDropZone'></form>
</div>
and this Javascript in the $(document).ready(function() {}
和这个 Javascript 在 $(document).ready(function() {}
window.Dropzone;
Dropzone.autoDiscover = false;
$('#fbDropZone').dropzone = {
init: function() {
fbDropZone = this;
$("#removeAllImages").click(function(){fbDropZone.removeAllFiles();})
},
paramName: "file",
maxFilesize: 5,
maxFiles : 1,
autoProcessQueue : false,
};
But the init:function()
isn't being executed. I can turn autoProcessQueue
to false
or true
and that works so I know the fbDropZone
id
is correct - but the maxFiles
is ignored as well. Have I done a daft syntax error somewhere..? I'm running Safari 7.
但是init:function()
没有被执行。我可以把autoProcessQueue
到false
或true
与该作品,所以我知道的fbDropZone
id
是正确的-但maxFiles
被忽略为好。我是不是在某处犯了一个愚蠢的语法错误..?我正在运行 Safari 7。
回答by Todd
It turns out that the code position is crucial: the dropzone calls have to be placed outside of the document loaded or ready function (I guess you'd call it inline).
事实证明,代码位置至关重要:dropzone 调用必须放在文档加载或就绪函数之外(我猜你会称之为内联)。
回答by Juls
Check that you have to Dropzone.autoDiscover = false
outside of your $(document).ready(...).
检查您是否必须Dropzone.autoDiscover = false
在您的$(document).ready(...).
Wrong:
错误的:
$(document).ready(function(){
Dropzone.autoDiscover = false;
$("#mydropzone").dropzone({
init: function() {...}
);
});
Right:
对:
Dropzone.autoDiscover = false;
$(document).ready(function(){
$("#mydropzone").dropzone({
init: function() {...}
);
});
回答by Breith
Try:
尝试:
Dropzone.autoDiscover = false;
$("#mydropzone").dropzone({
init: function() {
var $this = this;
$("button#clear-dropzone").click(function() {
$this.removeAllFiles(true);
});
},
paramName: "file",
maxFilesize: 5,
maxFiles : 1,
autoProcessQueue : false
});