Valums AJAX файл загрузки с несколькими кнопками загрузки - PullRequest
1 голос
/ 02 августа 2011

Я использую valums ajax file upload , и у меня возникли некоторые проблемы с наличием нескольких кнопок загрузки на одной странице.Может быть, я что-то упустил?

ниже приведен код кнопки загрузки 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

1 Ответ

2 голосов
/ 23 июля 2012

Ну, так как никто не ответил на это, и я держу пари, что люди сочтут это полезным, вот что я сделал:

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');

        }
    });
});

просто вставьте его в каждый, оберните функцию вокруг него, отправьте индексаааа и готово.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...