web上传本地图片预览操作总结

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <title>Load Image</title>
    <link rel="stylesheet" href="../static/css/bootstrap.min.css">
    <script src="../static/js/jquery-3.2.1.min.js"></script>
    <script src="../static/js/bootstrap.min.js"></script>
</head>
<script>
    /****上传图片****/
    var imgurl = "";  
    function loadLocalImge(node) {  
        var imgURL = "";  
        try{  
            var file = null;  
            if(node.files && node.files[0] ){  
                file = node.files[0];  
            }else if(node.files && node.files.item(0)) {  
                file = node.files.item(0);  
            }  
            try{  
                imgURL =  file.getAsDataURL();  
            }catch(e){  
                imgRUL = window.URL.createObjectURL(file);  
            }  
        }catch(e){  
            if (node.files && node.files[0]) {  
                var reader = new FileReader();  
                reader.onload = function (e) {  
                    imgURL = e.target.result;  
                };  
                reader.readAsDataURL(node.files[0]);   
            }  
        }  
        creatImg(imgRUL);  
        return imgURL;  
    }  
    function creatImg(imgRUL){
        $("#result_img").attr("src",imgRUL);      
    }  
</script>

<body style="background:url(../static/imags/body_bg.png)">
  <div class="container center-block">
    <div class="row">
        <div class="col-xs-12">
            <img id="result_img" src="../static/imags/result1.png" class="img-responsive center-block">
        </div>
    </div>
    <div class="row" style="margin-top: 2rem;margin-bottom: 2rem">
        <div class="col-xs-8 col-xs-push-2">
            <img src="../static/imags/share-btn.png" class="img-responsive center-block" onclick="onShareButtonClick()">
        </div>
    </div>
    <div class="row" style="margin-top: 2rem;margin-bottom: 2rem;">
        <div class="col-xs-8 col-xs-push-2">
            <label for="xFile"><img src="../static/imags/upload.png" class="img-responsive center-block"></label>  
            <input type="file" accept="image/png,image/jpg" name="uploadPicture" id="xFile" value="" title="上传照片" style="position:absolute;clip:rect(0 0 0 0);" onchange="loadLocalImge(this)"/>
             <!-- 隐藏input原生 上传按钮,使用图片替换  -->
        </div> 
    </div>
 </div>
</body>


</html>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值