Javascript Dropzonejs显示文件计数

Javascript Dropzonejs显示文件计数,javascript,Javascript,我正在一个网站上使用dropzonejs,到目前为止,它运行良好。但是,我想显示dropzone区域下方的文件数,以便用户可以看到他们添加了多少文件。我还使用一个按钮来控制myDropzone.processQueue 我遇到的问题是,我无法获取要在id=output的段落中显示的添加文件总数 这当然是因为我在JS方面是个新手,但我尝试在脚本中的不同“位置”设置变量,但没有效果 以下是我目前掌握的代码: <link rel="stylesheet" type="text/css" href

我正在一个网站上使用dropzonejs,到目前为止,它运行良好。但是,我想显示dropzone区域下方的文件数,以便用户可以看到他们添加了多少文件。我还使用一个按钮来控制myDropzone.processQueue

我遇到的问题是,我无法获取要在id=output的段落中显示的添加文件总数

这当然是因为我在JS方面是个新手,但我尝试在脚本中的不同“位置”设置变量,但没有效果

以下是我目前掌握的代码:

<link rel="stylesheet" type="text/css" href="css/dropzone.css">
<link rel="stylesheet" type="text/css" href="css/sweetalert.css">
<script src="js/dropzone.js"></script>
<script src="js/sweetalert.min.js"></script>

<script>

Dropzone.options.myDropzone = {


  // Prevents Dropzone from uploading dropped files immediately
  autoProcessQueue: false,


  init: function() {
    var submitButton = document.querySelector("#submit-all");
        myDropzone = this; // closure

    submitButton.addEventListener("click", function() {
      myDropzone.processQueue(); // Tell Dropzone to process all queued files.
    });

    // You might want to show the submit button only when 
    // files are dropped here:
    this.on("addedfile", function() {
      // Show submit button here and/or inform user to click it.
    var count = myDropzone.files.length;
    });



            this.on("success", function() {

               myDropzone.options.autoProcessQueue = true;
            });


            this.on("queuecomplete", function (file) {



                    setTimeout(function() {
            swal({
                title: "Thank you!",
                text: "Your upload is complete",
                type: "success",
                confirmButtonText: "Ok"
            }, function() {
                window.location = "index.html";
            }, 1000);
        });


            });
  }
};
</script>

<form action="send.php" class="dropzone" id="my-dropzone"></form>

<p id="output"></p>

<script>
document.getElementById("output").innerHTML = count;
</script> 

Dropzone.options.myDropzone={
//防止Dropzone立即上载删除的文件
自动处理队列:false,
init:function(){
var submitButton=document.querySelector(“全部提交”);
myDropzone=this;//闭包
addEventListener(“单击”,函数(){
myDropzone.processQueue();//告诉Dropzone处理所有排队的文件。
});
//您可能只想在以下情况下显示“提交”按钮:
//文件将放在此处:
this.on(“addedfile”,function()){
//在此处显示提交按钮和/或通知用户单击该按钮。
var count=myDropzone.files.length;
});
关于(“成功”,函数(){
myDropzone.options.autoProcessQueue=true;
});
此.on(“queuecomplete”,函数(文件){
setTimeout(函数(){
游泳({
标题:“谢谢!”,
文本:“您的上传已完成”,
键入:“成功”,
confirmButtonText:“好的”
},函数(){
window.location=“index.html”;
}, 1000);
});
});
}
};

document.getElementById(“输出”).innerHTML=count;

输出

Dropzone.autoDiscover=false; var myDropzone=新的Dropzone(“我的Dropzone”); myDropzone.on(“addedfile”,函数(文件){ var count=myDropzone.getAcceptedFiles().length; output=document.getElementById('output'); output.innerText=计数; });
你可以这样得到它
myDropzone.getAcceptedFiles().length
是的,我很抱歉这个愚蠢的问题,但是我如何以及在哪里在代码中实现它?这就是让我困惑的地方。谢谢看我的回答谢谢你,穆罕默德,工作起来很有魅力!