• HTML5手机端拍照上传


    1、accept="image/*" capture="camera" 自动调用手机端拍照功能

    accept="image/*" capture="camera"

    2、当表单提交时候有文件的时候,需要加上

    var formData = new FormData($( "form" )[0]);

    3、示例代码:

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
            <script src="http://code.jquery.com/jquery-2.1.1.min.js"></script>
            <title>HTML5手机端拍照上传</title>
            <style>
                 .list_box { 
                    display: -webkit-box;  
                    width: 90%; 
                    margin: 0px auto;   
                    border: 1px solid silver;
                    padding: 3px;
                    border-radius: 2px;
                 }
                .list {
                    width: 30%;
                    height: 100px;
                    border: 1px solid salmon;
                    margin-left: 2%;
                    display: block;
                    border:1px solid #4cd964; 
                    border-radius: 2px; 
                    background-size:100% 100%;
                    background-position: center center;
                    background-repeat: no-repeat;
                }  
                .list input {
                    width: 100%;
                    height: 100%;
                    opacity: 0;
                }
                input[type='submit']{
                    border: none;border-radius: 2px;
                    padding: 6px 22px;
                    display: block;
                    margin: 10px auto;
                    color: white;
                    background: #008000;
                }
            </style>
        </head>
        <body>
          <form method="" action=""  enctype="multipart/form-data" role="form">
             <div class="list_box">
                <a class="list" id="img0" href="javascript:;">
                    <input type="file" name="file1" accept="image/*" capture="camera" onchange="showImg(this)" />
                </a>
                <a class="list" id="img1" href="javascript:;">
                    <input type="file" name="file2" accept="image/*" capture="camera" onchange="showImg(this)" />
                </a>
                <a class="list" id="img2" href="javascript:;">
                    <input type="file" name="file3" accept="image/*" capture="camera" onchange="showImg(this)" />
                    <!--accept="image/*" capture="camera"-->
                </a>
            </div>
            <input type="submit" name="" id="btn" value="提交" />
            </form>
            <script> 
                 function showImg(e) {
                    var srcs0 = window.URL.createObjectURL(e.files[0]);
                    var index = e.parentNode.id; 
                    if(srcs0){
                        $('#'+index+'').css({"background":"url(" + srcs0 + ") center no-repeat","background-size": "100% 100%"});
                    }
                }
                 
            $("#btn").click(function(){
             $("#btn").css({"opacity":"0.8","disabled":"disabled"});
            $("#btn").val("正在提交,请耐心等待.....");
            var formData = new FormData($( "form" )[0]);
                 $.ajax({
                      url:"{php echo $this->createMobileUrl('dyfile', array('op' => 'fail'));}",
                      type: 'POST',
                      data: formData,    
                      contentType: false,
                      processData: false,
                      success: function (returndata) {
                        window.location.href="{php echo $this->createMobileUrl('dyorder', array('status' => '6'))}";
                      }
                 });
        });    
            </script>
        </body>
    </html>

     运行效果:

    选择文件之后:

  • 相关阅读:
    地税某数据库异常重启和重启后数据库运行缓慢问题的解决过程
    Oracle 索引 详解
    oracle数据库优化基本概念
    oracle物理读和逻辑读
    SQL 优化之该走索引却不走索引的分析(二)
    数据仓库中的分区修剪
    查询低效率的sql语句
    oracle优化的几个简单步骤
    VBS类似于ceil的函数
    ruby符号的应用
  • 原文地址:https://www.cnblogs.com/zhangyongl/p/7452395.html
Copyright © 2020-2023  润新知