首页 > 移动平台 > 详细

h5拉起手机摄像头拍照及选择图片并展示

时间:2019-11-25 16:58:09      阅读:322      评论:0      收藏:0      [点我收藏+]

1.html

<!--图片预览框 -->
<div style="height: 200px">
    <img src="" id="preview" style="width: auto;height: 100%">
</div>

<!-- 拍照-->
<input id="file1" type="file" accept="image/*" multiple capture="camera" onchange="show(1)"/>
<!-- 选图片 -->
<input id="file2" type="file" accept="image/*" mutiple onchange="show(2)">

 

2.js

  /*拍照或选择图片后的回调*/
    function show(val) {
        //获取到file
        var file = $("#file" + val).get(0).files[0];
        var reader = new FileReader();
     reader.onload = function () {
      $("#preview").attr("src",reader.result);
    }
     if(file){
      reader.readAsDataURL(file);
     }        
    }    

 

 

 

h5拉起手机摄像头拍照及选择图片并展示

原文:https://www.cnblogs.com/Mr-Yang-GS/p/11928476.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!