李晓龙
李晓龙
  • 发布:2015-07-02 13:18
  • 更新:2015-07-02 13:18
  • 阅读:4051

二维码的一些分享

分类:HTML5+

首先说说官方API有错误

第一点 在扫描的时候 必须有一个<div id="scan"></div> 的DIV这里 就不会在var e = document.getElementById("scan"); e.removeAttribute("disabled"); 这里报错了。

第二点 调用开启摄像头和关闭摄像头的时候
scan.setFlash(true); 要记得 里面设置参数

下面说问题

有些人说cancelScan这个方法不成功 在IOS上没有问题 但是 安卓上(小米4)在开启扫描的时候就崩溃了。但是IOS上一切都是正常的下面我贴出源码 看看

注意我引入了jquery用来一点点简单的事情,当让你也可以自己用DOM来操作。


<!DOCTYPE html>  
<html>  
<head>  
        <meta charset="utf-8">  
        <title>扫描测试</title>  
        <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">  
        <meta name="apple-mobile-web-app-capable" content="yes">  
        <meta name="apple-mobile-web-app-status-bar-style" content="black">  
               <link rel="stylesheet" href="../css/mui.min.css">  
        <!--App自定义的css-->  
        <link rel="stylesheet" type="text/css" href="../css/app.css" />  
<script src="../js/mui.min.js"></script>  
        <script src="../js/jquery-2.1.0.js" type="text/javascript" charset="utf-8"></script>  
        <script>  
             // 扩展API加载完毕后调用onPlusReady回调函数   
            document.addEventListener("plusready", onPlusReady, false);  
             // 扩展API加载完毕,现在可以正常调用扩展API  
            function onPlusReady() {  
                var e = document.getElementById("scan");  
                e.removeAttribute("disabled");  
                //startRecognize();  
                //startScan();  
            }  
            var scan = null;  
                      function onmarked(type, result) {  
                var text = '未知: ';  
                switch (type) {  
                    case plus.barcode.QR:  
                        text = 'QR: ';  
                        break;  
                    case plus.barcode.EAN13:  
                        text = 'EAN13: ';  
                        break;  
                    case plus.barcode.EAN8:  
                        text = 'EAN8: ';  
                        break;  
                }  
                embed = plus.webview.create(result, "", {  
                    top: "44px",  
                    bottom: "0px"  
                });  
                plus.webview.currentWebview().append(embed);  
                $("#cl").show();  
            }  
                     function startRecognize() {  
                scan = new plus.barcode.Barcode('bcid');  
                scan.onmarked = onmarked;  
            }  
                    function startScan() {  
                scan.start();  
            }  
                         function cancelScan() {  
                scan.cancel();  
            }  
                     function setcc() {  
                scan.setFlash(true);  
            }  
                   function closcc() {  
                scan.setFlash(false);  
            }  
                     function back() {  
                embed.close("slide-out-bottom");  
                $("#cl").hide();  
            }  
        </script>  
    </head>  
    <style type="text/css">  
        * {  
            -webkit-user-select: none;  
        }  
        html,  
        body {  
            margin: 0px;  
            padding: 0px;  
            height: 100%;  
        }  
        #bcid {  
            height: 260px;  
            width: 100%;  
        }  
        button {  
            margin-left: 2px;  
            margin-top: 2px;  
            width: 31%;  
        }  
    </style>  
       <body>  
        <header class="mui-bar mui-bar-nav">  
            <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>  
            <a id="cl" onclick="back()" class=" mui-icon  mui-pull-right " style="font-size: 0.8em;margin-top: 5px;display: none;">关闭</a>  
            <h1 class="mui-title">set</h1>  
        </header>  
        <div class="mui-content">  
            <!--<input type='button' onclick='startRecognize()' value='创建扫描控件' />  
            <input type='button' onclick='startScan()' value='开始扫描' />  
            <input type='button' onclick='cancelScan()' value='取消扫描' />  
            <input type='button' onclick='setFlash()' value='开启闪光灯' />-->  
            <div id="bcid">  
                           <div id="scan"></div>  
            </div>  
            <input type='text' id='text' />  
        </div>  
        <button type="button" class="mui-btn mui-btn-primary" onclick="startRecognize()">获取扫描窗口</button>  
        <button type="button" class="mui-btn mui-btn-primary" onclick="startScan()">开始扫描</button>  
        <button type="button" class="mui-btn mui-btn-primary" onclick="setcc()">开启闪光灯</button>  
        <button type="button" class="mui-btn mui-btn-primary" onclick="closcc()">关闭闪光灯</button>  
        <button type="button" class="mui-btn mui-btn-primary" onclick="cancelScan()">结束扫描</button>  
</body>  
</html>
2015-07-02 13:18 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复