2016-03-02 71 views
0

我已經使用jquery文件上傳插件(https://github.com/blueimp/jQuery-File-Upload)完成文件上傳。但現在,我不知道如何解決這個問題:我有HTML代碼:jQuery文件上傳多個實例錯誤

<form id="form-1"></form> 
<input type="file" class="file-upload" id="file-1" name="file" form="form-1" /> 
<form id="form-2"></form> 
<input type="file" class="file-upload" id="file-2" name="file" form="form-2" /> 




    $('input[type="file"][name="file"].file-upload').each(function(){ 
      var self = $(this); 
      $(this).fileupload({ 
       url: window.fileUpload.uploadUrl, 
       dataType: 'json', 
       dropZone: self, 
       fileInput: self 
      }); 
}); 

但是有問題,當我把文件在第一輸入,其上傳文件的2倍 - 爲每個輸入。而我不知道,如何解決這個問題。你有任何解決方案?

編輯: 我發現,上傳只做了一次,但兩次被稱爲「fileuploaddone」事件。

解決: jQuery文件上傳實例在一個文件輸入上啓動了兩次。

回答

0

這是因爲你不進口jquery的最小的js文件和<script type="text/javascript">您的代碼在這裏</script>

+0

下正確地編寫代碼你是什麼意思呢?我使用jQuery。我使用「https://code.jquery.com/jquery-2.1.4.min.js」。我通過ajax加載的表單,以便在ajax完成時調用代碼來初始化fileupload。 –