duangangpin078794 2012-07-03 00:58
浏览 64
已采纳

图像上传输入:1个输入,最多需要4个上传

I am right now working with this image upload from HERE. Instead of having 3 separate image upload inputs is there a way to just have one that will take maximum 4 requests?

<script>
(function($) {

$(document).ready(function() {

    // it must be checked if there are div.imageForms because the
    // uploaderPreviewer javascript may be not included and produce an error
    if ($('div.imageForms').length) {

    $.uploaderPreviewer.formsCount = 4;

        $('div.imageForms').append($.uploaderPreviewer.createImageForms());

        // the images are populated if the admin form is to edit, and not
        // to insert
        if ($('div.imageForms[images]').length) {
            var imageFilenames = $('div.imageForms[images]').attr('images').split(',');
            $.uploaderPreviewer.populateImages(imageFilenames);
            $('div.imageForms[images]').removeAttr('images');
        }
    }

    $('#buttonSave').click(function() {
        var itemId = $(this).attr('itemId');
        if (itemId) {
            $.itemForm.update(itemId);
        }
        else {
            $.itemForm.insert();
        }
    });

});

})(jQuery);



</script>
  • 写回答

1条回答 默认 最新

  • dream12001 2012-07-03 01:08
    关注

    If you don't care about IE then you can use a multiple file input an let users select no more than 4 files. I added a simple fallback for IE in which it will only get one file, so you might want to use multiple inputs just for IE. Damn Internet Explorer!

    <input id="files" type="file" multiple />
    

    .

    var isValidFiles = function ($input, max) {
      var files = $input[0].files || [{ name: $input.val() }]
      return files.length <= max
    }
    

    .

    if ( isValidFiles($('#files'), 4) ) { ... }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接
  • ¥15 MCNP里如何定义多个源?
  • ¥20 双层网络上信息-疾病传播
  • ¥50 paddlepaddle pinn
  • ¥20 idea运行测试代码报错问题
  • ¥15 网络监控:网络故障告警通知
  • ¥15 django项目运行报编码错误
  • ¥15 STM32驱动继电器