zoukankan      html  css  js  c++  java
  • H5调用手机拍照并展示在前端页面

    <!DOCTYPE html>
    <html lang="en">
    
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>手机拍照</title>
        <style>
            #showimg{
                width: 150px;
                height: 150px;
            }
            #file_input{
                opacity: 0;
                position: absolute;
                width: 100%;
                height: 100;
            }
            #box{
                position: relative;
                background: green;
            }
        </style>
    </head>
    
    <body>
        <div class="file-box" id="box">
            拍照上传
            <input type="file" accept="image/*" capture="camera" id="file_input" class="file-btn">
        </div>
    
        <img id="showimg">
    </body>
    
    </html>
    
    <script>
        var showimg = document.getElementById("showimg");
        var imginput = document.getElementById("file_input");
        document.getElementById("box").onclick = function () {
            imginput.onchange = function () {
                var files = this.files;
                console.log(files)   //本地的临时路径
              
                   // var formdata = new FormData();
                    //formdata.append('fileStream', files);
             // formdata再传给后台

    var url = URL.createObjectURL(files[0]); showimg.src = url; } } </script>
  • 相关阅读:
    Redis事务和锁
    11/6笔记 补充(Redis持久化,RDB&&AOF)
    11/6随笔
    Redis 安装教程
    Redis通用指令和第一个Jedis程序的实现
    Redis学习第二天
    SpringBoot学习笔记
    1000行代码手写服务器
    log4j创建实例异常
    寒假阅读人月神话3
  • 原文地址:https://www.cnblogs.com/teamemory/p/9668992.html
Copyright © 2011-2022 走看看