获取jQuery Dropzone DIV的属性

时间:2014-05-02 18:39:08

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

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

  1. 如果仅在点击提交按钮(不使用每个dropzone的表单)后才能上传所有dropzones中的所有文件?当我将autoProcessQueue设置为false并尝试附加侦听器时,显示无法将事件附加到undefined的错误显示...
  2. 如何获取dropzone对象的属性,例如的rel =" 6"第一个掉落区?尝试使用this.attr(' rel')/ $(this).attr(' rel')会导致' undefined' ...
  3. 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 }
                });
            });
        }
    }
    

0 个答案:

没有答案