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

时间:2019-11-25 16:58:09   收藏:0   阅读:322

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);
     }        
    }    

 

 

 

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

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!