2012-09-13 22 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"); 
      }) 
     } 
    }) 
}); 
相关问题