【问题标题】:Getting attribute of jQuery Dropzone DIV获取jQuery Dropzone DIV的属性
【发布时间】:2014-05-02 18:39:07
【问题描述】:

我的每个引导选项卡中都有 dropzone (v3.7.1) div。

  1. 如何仅在单击提交按钮后上传所有拖放区中的所有文件(不为每个拖放区使用表单)?当我将 autoProcessQueue 设置为 false 并尝试附加侦听器时,出现无法将事件附加到未定义的错误...
  2. 如何获取 dropzone 对象的属性,例如第一个放置区的 rel="6"?尝试使用 this.attr('rel') / $(this).attr('rel') 会导致 'undefined'...

HTML

<form class="my-form" method="post">
    <input type="text" name="form-input-1" id="form-input-1" />
    <input type="text" name="form-input-2" id="form-input-2" />

    <div class="tab-content">
        <div class="tab-pane active" id="ic_6">
            <h3>Overview</h3>
            <div rel="6" class="dropzone" id="my-dropzone"></div>
        </div>
        <div class="tab-pane" id="ic_1">
            <h3>Living Room</h3>
            <div rel="1" class="dropzone" id="my-dropzone"></div>
        </div>
        <div class="tab-pane" id="ic_2">
            <h3>Kitchen</h3>
            <div rel="2" class="dropzone" id="my-dropzone"></div>
        </div>
        <div class="tab-pane" id="ic_3">
            <h3>Bathroom</h3>
            <div rel="3" class="dropzone" id="my-dropzone"></div>
        </div>
        <div class="tab-pane" id="ic_4">
            <h3>Bedroom</h3>
            <div rel="4" class="dropzone" id="my-dropzone"></div>
        </div>
        <div class="tab-pane" id="ic_5">
            <h3>Outdoors</h3>
            <div rel="5" class="dropzone" id="my-dropzone"></div>
        </div>
    </div>

    <button type="submit">Submit</button>
</form>

JS

Dropzone.options.myDropzone = {
    url: "upload.php", 
    maxFilesize: 2, // MB
    addRemoveLinks: true, 
    acceptedFiles: "image/*", 
    accept: function(file, done) {
        console.log("uploaded");
        done();
    },
    init: function() {
        this.on("addedfile", function(file) {
            //== divider ==//
            var dividerElement = Dropzone.createElement("<div>&nbsp;</div>");
            file.previewElement.appendChild(dividerElement);

            //== caption input : still trying to figure capturing this ==//
            var captionInput = Dropzone.createElement("<input type='text' name='caption' maxlength='50' placeholder='Enter a caption' />");
            file.previewElement.appendChild(captionInput);
        });

        this.on("removedfile", function(file) {
            $.ajax({
                url: "delete_temp_files.php",
                type: "POST",
                data: { filename: file.name }
            });
        });
    }
}

【问题讨论】:

    标签: javascript jquery html twitter-bootstrap dropzone.js


    【解决方案1】:

    我知道这是一篇旧帖子,但访问原始元素属性的解决方案是 console.log($($(this)[0].element).attr("rel"));

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-10-21
      • 2010-12-30
      • 1970-01-01
      • 2012-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多