2012-09-13 19 views
0

我正在使用this jQuery api來處理帶有狀態欄的文件上傳。我有以下(工作)代碼:使用jQuery從動態添加的輸入字段上傳文件

$(".imageinput") 
    .live("fileuploadadd", function(e, data) { 
     data.dataType = "json"; 
    }) 
    .live("fileuploadsend", function(e, data) { 
     data.dataType = "json"; 
     debugger; 
     $(
      '<div id="paragraph"' + createNewParagraphID() + '" class="new paragraph image">' + 
       '<div class="progressbar"></div>' + 
      '</div>' + 
      controlDiv + createNewParagraph() 
     ).insertAfter($(this).parent()); 
    }) 
    .live("fileuploadprogressall", function(e, data) { 
     data.dataType = "json"; 
     var bar = $(this).parent().next().children().css("width", parseInt(100 * data.loaded/data.total, 10) + "%"); 
    }) 
    .live("fileuploaddone", function(e, data) { 
     data.dataType = "json"; 
     $.each(data.result, function(index, file) { 
      console.log("done"); 
     }); 
    }); 

我需要使用下面的代碼才能獲得有關服務器上載狀態的響應。由於可以動態添加元素,因此我需要使用實時方法。

$(".imageinput").fileupload({ 
    dataType: "json" 
}); 

如何使用動態添加的元素在此api中設置數據類型?

回答

0

,我發現自己的答案:

$(".imageinput").live("hover", function(e) { 
    $(".imageinput").fileupload({ 
     dataType: "json", 
     start: function(e) { 
      $(
       '<div id="paragraph"' + createNewParagraphID() + '" class="new paragraph image">' + 
        '<div class="progressbar"></div>' + 
       '</div>' + 
       controlDiv + createNewParagraph() 
      ).insertAfter($(this).parent()); 
     }, 
     progressall: function(e, data) { 
      var bar = $(this).parent().next().children().css("width", parseInt(100 * data.loaded/data.total, 10) + "%"); 
     }, 
     done: function(e, data) { 
      $.each(data.result, function(index, file) { 
       console.log("done"); 
      }) 
     } 
    }) 
}); 
相關問題