input批量上传照片

<html>
<head>
   <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
</head>
<body>
<div>
    <input type="file" id="image" capture="camera" accept="image/jpeg" multiple="multiple"/>
</div>
<div id="images">
</div>
<script>
var count = 0;
var files = [];
var reader = new FileReader();
var AllowImgFileSize = 787500; //上传图片最大值(单位字节)( 2 M = 2097152 B )超过2M上传失败 2100000
var images = [];
function upload(){
      images = [];
      count = 0;
        files = $("#image")[0].files;
      readImg();
    }
function readImg(){
   var file = files.item(count);
   if (file) {
      //将文件以Data URL形式读入页面  
      reader.readAsDataURL(file);
      reader.onload = function (e) {
        if (AllowImgFileSize != 0 && AllowImgFileSize < reader.result.length) {
            alert(files.item(count).name+ '上传失败,请上传不大于750K的图片!');
            return;
         }else{
            images[count] = {name:files.item(count).name,code:reader.result}
            count++;
            readImg(files);
         }
      }
    }else{
      count = 0;
        var html = '';
      for(var i in images){
         html += '<img title="'+images[i].name+'" style="width:150px;height:150px;margin:10px;" src="'+images[i].code+'">';
      }
        $("#images").html(html);
    }
}
    $(function(){
        $("#image").change(function(){
            upload();
        });
    })
</script>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值