s***@gmail.com
s***@gmail.com
  • 发布:2018-11-01 15:17
  • 更新:2019-11-13 16:28
  • 阅读:1975

【报Bug】barcode的方法 create 范例有误

分类:HTML5+

下边是在http://www.html5plus.org/doc/zh_cn/barcode.html#plus.barcode.create的范例代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Barcode Example</title>
<script type="text/javascript" >
var barcode = 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;
}
alert( text+result );
}
// 创建Barcode扫码控件
function createBarcode() {
if(!barcode){
barcode = plus.barcode.create('barcode', [plus.barcode.QR], {
top:'100px',
left:'0px',
width: '100%',
height: '200px',
position: 'static'
});
....代码太多不再贴了,详情可查看上方的网址

用上边的这段代码建立的barcode扫描器会导致APP闪退,我找了一下原因,发现是参数三的值导致的,下边是我写的代码,贴出来给你们做个参考吧~!

var barcode=null;
function _createBarcode() { //创建扫码控件
if(!barcode){
barcode=plus.barcode.create(
'barcode1',
[plus.barcode.QR],
{top:'250px',left:'0',width:'100%',height:'300px',position:'absolute'}
);

    barcode.setFlash(true);  
    barcode.onmarked=function(type,code){  
        var typ={};  
            typ[0]='QR二维码';  
            typ[1]='EAN条形码标准版';  
            typ[2]='EAN条形码简版';  
            typ[3]='Aztec二维码';  
            typ[4]='Matrix二维码';  
            typ[5]='UPCA条形码标准版';  
            typ[6]='UPCE条形码缩短版';  
            typ[7]='CODABAR条形码';  
            typ[8]='CODE39条形码';  
            typ[9]='CODE93条形码';  
            typ[10]='CODE128条形码';  
            typ[11]='ITF条形码';  
            typ[12]='MAXICODE二维码';  
            typ[13]='PDF417二维条码';  
            typ[14]='RSS14条形组合码';  
            typ[15]='扩展式RSS条形组合码';  
        barcode.close();  
        alert('掃描成功,類型是:'+typ[type]+' 內容是:'+code);  
        types=barcode=null;  
    }  
    barcode.onerror=function(error){  
        barcode.close();  
        types=barcode=null;  
        alert(error);  
    }  
    plus.webview.currentWebview().append(barcode);  
}barcode.start();  

plus.nativeUI.toast('若不進行掃描的動作一會就自動關閉掃碼控件!',{duration:'long'});  
window.setTimeout(function(){ //延迟10秒查找扫码控件  
    if(barcode){  
        alert('找到了扫码控件');  
        barcode.close();  
        barcode=null;  
    } else {  
        alert('沒找到扫码控件');  
        barcode=null;  
    };  
},10000);  

}

2018-11-01 15:17 负责人:无 分享
已邀请:
s***@gmail.com

s***@gmail.com (作者) - www.7di.net

你们这个论坛应该是有bug的,主贴里我直接贴了代码,他竟然自动把一部分代码给用表格框起来了,这有点奇怪

叶南淮

叶南淮

请问解决了吗 我也是报参数3,而且奇怪的是,有的码能扫到,有的扫不到

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