• html5 图片上传 预览


    <html>
    <body>
    <fieldset>
    <legend>测试</legend>
    <div class="form-group">
    <div class="img-preview rl">
    <form id="index_form1" name="index_form1" role="form" method="post" enctype="multipart/form-data" style="float: left;">

    <div class="mui-col-xs-4 img-upload mui-text-center iconfont icon-shangchuantupian rl mui-pull-left" id="picone" style="background-image: url(imgs/andd.png);background-size:cover ;">
    <span style="font-size: 15px; padding-left: 20px; position: absolute; float: left; margin-top: 104px;">测试</span>
    <input type="file" class="wid-100 ab file" id="uploadpic1" name="uploadpic1"  capture="camera"   accept="image/*"  onchange='doChange(this)'; />

    <div class="mui-clearfix"></div>
    </div>

    </form>

    </div>
    </div>
    </fieldset>

    <img id="img1" src="a.jpg" style="200px;height:200px"/>
    </body>
    </html>

    <script>
    
        if (typeof FileReader == 'undefined') {
            alert("抱歉,你的浏览器不支持FileReader");
        }
    
    function doChange(obj)
    {
        html5ImgLocalReader('uploadpic1', 'img1');
    }
    
    function html5ImgLocalReader(fileId, imgId) {
        var file1 = document.getElementById(fileId);
        var file = file1.files[0];    
        var reader = new FileReader();
        reader.readAsDataURL(file);
    
        reader.onload = function (e) {
            document.getElementById(imgId).src=this.result;
            //document.getElementById(imgId).style.backgroundImage = "url("+this.result+")";
        }
    }
    </script>
    

      

    From:http://www.cnblogs.com/xuejianxiyang/p/6845162.html

  • 相关阅读:
    剑指offer_24:二叉树中和为某一值的路径
    剑指offer_23:二叉搜索树的后序遍历序列
    Java基础类型大小
    旋转数组
    剑指offer_22:从上往下打印二叉树
    剑指offer_21:栈的压入、弹出序列
    剑指offer_20:包含min函数的栈
    剑指offer_19:顺时针打印矩阵
    剑指offer_18:二叉树的镜像
    redis jedis源码
  • 原文地址:https://www.cnblogs.com/xuejianxiyang/p/6845162.html
Copyright © 2020-2023  润新知