簡體   English   中英

動態使用bleuimp jQuery文件上傳

[英]Dynamically use bleuimp jquery file upload

我正在使用blueimp JQuery fileupload ,但是我想動態使用它。 我的網頁上有大約5個元素,並且在選擇文件后,每個元素都應調用javascript函數(自動上傳)。 以下是bleuimp JQuery文件上傳的基本版本。 我沒有使用一個名為#fileupload的div,而是將5個div的ID為#fileupload1#fileupload5

我想使用單個javascript塊使所有5 #fileupload id的javascript代碼正常工作。 因此,基本上,我希望對所有5個元素使用下面的代碼。 有沒有辦法做到這一點,如果有的話,有人為我提供榜樣嗎? 謝謝你的幫助。

$(function () {
    'use strict';
    // Change this to the location of your server-side upload handler:
    var url = window.location.hostname === 'blueimp.github.io' ?
                '//jquery-file-upload.appspot.com/' : 'server/php/';
    $('#fileupload').fileupload({
        url: url,
        dataType: 'json',
        done: function (e, data) {
            $.each(data.result.files, function (index, file) {
                $('<p/>').text(file.name).appendTo('#files');
                alert('DONE');
            });
        },
        progressall: function (e, data) {
            var progress = parseInt(data.loaded / data.total * 100, 10);
            $('#progress .progress-bar').css(
                'width',
                progress + '%'
            );
        }
    }).prop('disabled', !$.support.fileInput)
        .parent().addClass($.support.fileInput ? undefined : 'disabled');
});

我找到了解決方案。 也許不是最好的,但到目前為止它對我有用。

$('.dp-upload-container').each(function () {
// Code from $(function() { }); here using different ID's and classes dynamically.
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM