zoukankan      html  css  js  c++  java
  • 整理几个js上传多张图片的效果

    一、普通的上传图片,张数不限制

    <!DOCTYPE HTML>
    <html>
    <head>
        <meta charset="UTF-8">
        <title>上传多张图片</title>
        <style type="text/css">
            .img-div{
                border: 1px solid #ddd;
                border-radius: 100%;
                float: left;
                line-height: 1;
                margin-left: 5px;
                overflow: hidden;
            }
    
        </style>
    </head>
    <body>
    
    <script type="text/javascript">
        //选择图片,马上预览
        function xmTanUploadImg(obj) {
    
            var fl=obj.files.length;
            for(var i=0;i<fl;i++){
                var file=obj.files[i];
                var reader = new FileReader();
    
                //读取文件过程方法
                reader.onloadstart = function (e) {
                    console.log("开始读取....");
                }
                reader.onprogress = function (e) {
                    console.log("正在读取中....");
                }
                reader.onabort = function (e) {
                    console.log("中断读取....");
                }
                reader.onerror = function (e) {
                    console.log("读取异常....");
                }
                reader.onload = function (e) {
                    console.log("成功读取....");
    
                    var imgstr='<img style="100px;height:100px;" src="'+e.target.result+'"/>';
                    var oimgbox=document.getElementById("imgboxid");
                    var ndiv=document.createElement("div");
    
                    ndiv.innerHTML=imgstr;
                    ndiv.className="img-div";
                    oimgbox.appendChild(ndiv);
                   
                }
                reader.readAsDataURL(file);
            }
        }
    </script>
    <form id="form">
        <input type="file" id="xdaTanFileImg"  multiple="multiple"  name="fileAttach" onchange="xmTanUploadImg(this)"/>
        <div class="img-box" id="imgboxid"></div>
        <div id="xmTanDiv"></div><br/>
        <div id="errordiv" style="margin-top:15px;100%;text-align:center;">
    </div>
    </form>
    </body>
    

    二、限制图片张数、图片大小、图片宽高、删除图片

    整理中...

  • 相关阅读:
    Ubuntu 16.04 设置静态IP 注意事项
    C++ Primer: 1. 初识输入和输出
    车牌识别1:License Plate Detection and Recognition in Unconstrained Scenarios阅读笔记
    梳理检测论文-Refinement Neural Network
    linux 的 磁盘管理
    ubuntu 18 设置语言环境
    Ubuntu 18.04 的网络配置
    YoLo 实践(1)
    Distributed TensorFlow
    MXNet 分布式环境部署
  • 原文地址:https://www.cnblogs.com/wangjae/p/7363672.html
Copyright © 2011-2022 走看看