第一步:

  

  上面这段代码写在index.html里面,我也不知道为什么,可能是全局的关系;

第二步:

  

  定义一个按钮,点击启动扫码功能,另外再定义一个盒子来当做扫码的容器;我给这个盒子定义了一个id类名:bcid

第三步: 第三步代码多,直接粘贴,方便你我他,我也是在别人手上抄过来,作了部分改变

    

//创建扫描控件
startRecognize1() {
document.getElementById('bcid').style.display = 'block';
document.getElementsByClassName('scanCode')[0].style.display = 'none';
let that = this;
if (!window.plus) return;
scan = new plus.barcode.Barcode('bcid');
scan.onmarked = onmarked;
setTimeout(function(){
that.startScan1();
},100)

function onmarked(type, result, file) {
switch (type) {
case plus.barcode.QR:
type = 'QR';
break;
case plus.barcode.EAN13:
type = 'EAN13';
break;
case plus.barcode.EAN8:
type = 'EAN8';
break;
default:
type = '其它' + type;
break;
}
result = result.replace(/\n/g, '');
that.codeUrl = result;
alert(that.codeUrl);
if(that.codeUrl){
that.cancelScan1();
that.closeScan1();
}
}
},
//开始扫描
startScan1() {
if (!window.plus) return;
scan.start();
},
//关闭扫描
cancelScan1() {
if (!window.plus) return;
scan.cancel();
},
//关闭条码识别控件
closeScan1() {
document.getElementById('bcid').style.display = 'none';
document.getElementsByClassName('scanCode')[0].style.display = 'block';
if (!window.plus) return;
scan.close();
},

————————————————————————————————————————————————————————————————————————————————————————————

  

  

最新文章

  1. iOS 应用评分
  2. Ubuntu14.04台式机r8169有线网卡驱动问题
  3. project 2016 11 20 树的多项式
  4. 二进制求最大公约数&&输出二进制
  5. Windows Azure Traffic Manager (5) Traffic Manager Overview
  6. 招聘一个靠谱的 iOS
  7. 【转】【SEE】基于SSE指令集的程序设计简介
  8. CSS 仿Excel表格功能
  9. Laravel Repository 模式
  10. servlet 默认是线程安全的吗?
  11. c# winfrom 委托实现窗体相互传值
  12. C++中的 new / delete
  13. Visual Studio 中用管理员权限运行、调试程序
  14. 特征选择(三)-K-L变换
  15. PHP header( ) 禁止页面后退
  16. random模块函数分析(一)
  17. Linux下添加源的几种方法
  18. 让你的代码减少三倍!使用kotlin开发Android(五) 监听器
  19. Linux之mailx的使用
  20. SpringBoot入门教程(十二)DevTools热部署

热门文章

  1. python练习:异常
  2. VS.NET(C#)--2.8_CCS样式
  3. Spark机器学习基础-监督学习
  4. 关于微信小程序iOS端时间格式兼容问题
  5. selenium异常
  6. array_map 去除数组参数里面左右两端空格
  7. Linux文件(夹)属性
  8. 运维开发笔记整理-JsonResponse对象
  9. 二进制部署kubernetes集群(上篇)
  10. 纯js验证码