简体   繁体   English

dropzone.js - 我如何发布动态 div id

[英]dropzone.js - how can I post dynamic div id

I try to upload files with dropzone.js.我尝试使用 dropzone.js 上传文件。 My problem is that I have four dropzone upload containers on one page for different images.我的问题是我在一个页面上有四个 dropzone 上传容器,用于不同的图像。 How can I post the selected div to the post event?如何将选定的 div 发布到 post 事件?

<div class='product_thumbs'>
  <form name="product_image_1" action="ajax/upload.php" class="dropzone">
    <div class="product_image image_1" id="image_1">
      <div class="fallback">
        <i class="fa fa-upload"></i>
        <input id="file_1" type="file" multiple />
      </div>
    </div>
    <div class="product_image image_2" id="image_2">
      <div class="fallback">
        <i class="fa fa-upload"></i>
        <input id="file_2" type="file" multiple />
      </div>
    </div>
    <div class="product_image image_3" id="image_3">
      <div class="fallback">
        <i class="fa fa-upload"></i>
        <input id="file_3" type="file" multiple />
      </div>
    </div>
    <div class="product_image image_4" id="image_4">
      <div class="fallback">
        <i class="fa fa-upload"></i>
        <input id="file_4" type="file" multiple />
      </div>
    </div>
  </form>
</div>
$(document).ready(function() {
  $(".image_1, .image_2, .image_3, .image_4").dropzone({
    url: "ajax/upload.php?product_id=" + $("#product_id").val() + "&image_number=" + $(this.element).data("id"), // Here I´ll post the id
      thumbnailWidth: 100,
      thumbnailHeight: 120,
      addRemoveLinks: false,
      previewTemplate: ""+
        "<div class=\"dz-preview dz-file-preview\">"+
        "<div class=\"dz-details\">"+
        //"<div class=\"dz-filename\"><span data-dz-name></span></div>"+
        //"<div class=\"dz-size\" data-dz-size></div>"+
        "<img data-dz-thumbnail />"+
        "</div>"+
        "<div class=\"dz-progress\"><span class=\"dz-upload\" data-dz-uploadprogress></span></div>"+
        "<div class=\"dz-error-message\"><span data-dz-errormessage></span></div>"+
        "</div>"
    });
});

How can I edit the URL after adding an image?添加图像后如何编辑 URL? I will post also the class or id of the selected file container...我还将发布所选文件容器的类或 ID...

Try This:尝试这个:

$(this).attr("id")

to get the id of current div获取当前div的id

I'm not sure what you're trying to achieve.我不确定你想要达到什么目标。

If you wish to simply post all of the input files give them all the same name eg name="file[]" the [] mean it's an array.如果您希望简单地发布所有输入文件,请为它们提供相同的名称,例如name="file[]" [] 表示它是一个数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM