2011-08-02 11 views
1

valums ajax file upload을 사용하고 있으며 동일한 페이지에 여러 개의 업로드 버튼이있는 데 몇 가지 문제가 있습니다. 나는 뭔가를 놓칠 수 있습니까?여러 업로드 버튼이있는 valums ajax 파일 업로드

아래는 업로드 버튼 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'); 

     } 
    }); 
}); 

그냥 주위에 기능을 각에 넣어 포장의를 보내 색인, 끝났어.

+1

위대한 작품. 아직도, 다른 사람들이 이것이 janky라고 생각합니까? 클래스는 단일 요소가 아닌 선택기를 수락하고이를 정상적으로 처리해야합니다. – jMyles