2011-08-02 45 views
1

我使用的是valums ajax file upload,我在同一頁面上有多個上傳按鈕時遇到了一些問題。可能是我錯過了什麼?valums ajax fileupload具有多個上傳按鈕

下面是代碼1的上傳按鈕。

<div id="file-uploader-demo1">  
    <noscript>   
     <p>Please enable JavaScript to use file uploader.</p> 
     <!-- or put a simple form for upload here --> 
    </noscript>   
</div> 


<script>   
    function uploader(){    
     var uploader1 = new qq.FileUploader({ 
      element: document.getElementById('file-uploader-demo1'), 
      action: 'do-nothing.htm', 
      debug: true 
     });   
    } 
    // in your app create uploader as soon as the DOM is ready 
    // don't wait for the window to load 
    window.onload = uploader;  

</script>  

謝謝。 Aanu

+0

你有什麼問題? –

+0

如果我創建另一個按鈕,它甚至沒有顯示,也沒有錯誤信息。 – Aanu

+0

固定。只需向Uploader()函數傳遞一個唯一參數即可解決問題。 – Aanu

回答

2

那麼,既然沒有人理會這一點,我敢打賭,人們會發現它有用的,這是我做的:

jQuery('.btnUploader').each(function (index) { 
    var uploader1 = new qq.FileUploader({ 

     element: jQuery('.btnUploader')[index], // The HTML element to turn into the uploader 

     action: getUrl('ControllerUploadHandler', 'Home'), // Action method that will handle the upload 

     multiple: false, // Single or Mutliple file selection 

     allowedExtensions: ['png', 'jpeg', 'jpg', 'gif', 'bmp'], // File Type restrictions 

     sizeLimit: 0, // Max File Size 
     minSizeLimit: 0, // Min File Size 

     debug: false, // When true outputs server response to browser console 

     // Show a preview of the uploaded image 
     onComplete: function (id, fileName, responseJSON) { 

      //   // Get the preview container 
      //   var $previewContainer = jQuery('#uploader1Preview'); 

      //   // Create the preview img element 
      //   var $preview = jQuery('<img />'); 
      //   // Add the current time to the end of the preview handler's url to prevent caching by the browser 
      //   $preview.attr('src', getUrl() + 'Content/handlers/previewPhoto.ashx?filename=' + fileName + '&v=' + new Date().getTime()); 
      //   // Hide the preview and set it's size 
      //   $preview.css({ display: 'none', width: '90%', height: '200px' }); 

      //   // Make sure the preview's container is empty 
      //   $previewContainer.html(''); 
      //   // Append the preview to the container 
      //   $previewContainer.append($preview); 

      //   // Fade in the preview 
      //   $preview.fadeIn('slow'); 

     } 
    }); 
}); 

只是把它的每一個,包裝的功能周圍,發索引,aaa並完成。

+1

偉大的工作。儘管如此,還有其他人認爲這是不是很瘋狂?這個類需要接受一個選擇符而不是一個單一的元素,並且優雅地處理它。 – jMyles