Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/477.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 英特尔xdk 2条码扫描仪_Javascript_Html_Intel Xdk - Fatal编程技术网

Javascript 英特尔xdk 2条码扫描仪

Javascript 英特尔xdk 2条码扫描仪,javascript,html,intel-xdk,Javascript,Html,Intel Xdk,我正在尝试将2个条形码扫描仪安装到2个不同的按钮上。问题是,当我按下一个或另一个按钮时,两个脚本都与每个按钮一起使用。我需要怎样把它们分开 按钮1: <a class="uib-graphic-button default-graphic-sizing default-image-sizing hover-graphic-button active-graphic-button default-graphic-button default-graphic-text widget uib_w

我正在尝试将2个条形码扫描仪安装到2个不同的按钮上。问题是,当我按下一个或另一个按钮时,两个脚本都与每个按钮一起使用。我需要怎样把它们分开

按钮1:

<a class="uib-graphic-button default-graphic-sizing default-image-sizing hover-graphic-button active-graphic-button default-graphic-button default-graphic-text widget uib_w_52 d-margins skenavimo_tekstas media-button-text-bottom" data-uib="media/graphic_button"
                data-ver="0" id="scan1" style="position: relative; display:block; float:center; width: 10%; padding-bottom: 10%;
width: 50%; margin: 0 auto; " onclick="scanNow();">

按钮2:

<a class="button widget uib_w_54 d-margins testas icon camera yellow" data-uib="app_framework/button" data-ver="1" id="scan2" onclick="scanNow2();">Scan</a>
扫描
脚本1:

 <script>
        function scanNow()
            {
                //this function launches the QR Code scanner.
                intel.xdk.device.scanBarcode();
            }
            document.addEventListener("intel.xdk.device.barcode.scan",function(evt){
                if (evt.success == true) {
                    //successful scan
                   alert("I'm number 1");
                }
                else 
                {
                    //failed scan
                    alert("ERROR");
                }
            },false);
    </script>

函数scanNow()
{
//此功能启动二维码扫描仪。
intel.xdk.device.scanBarcode();
}
document.addEventListener(“intel.xdk.device.barcode.scan”,函数(evt){
如果(evt.success==true){
//扫描成功
警惕(“我是第一号”);
}
其他的
{
//扫描失败
警报(“错误”);
}
},假);
脚本2:

<script>
    function scanNow2()
            {
                //this function launches the QR Code scanner.
                intel.xdk.device.scanBarcode();
            }
   document.addEventListener("intel.xdk.device.barcode.scan",function(ted){
                if (ted.success == true) {
                    //successful scan
                alert("I'm nubmer 2");
                }else{
               //failed scan
                    alert("ERROR");
                }
             },false);
    </script>

函数scanNow2()
{
//此功能启动二维码扫描仪。
intel.xdk.device.scanBarcode();
}
document.addEventListener(“intel.xdk.device.barcode.scan”,函数(ted){
if(ted.success==true){
//扫描成功
警惕(“我是nubmer 2”);
}否则{
//扫描失败
警报(“错误”);
}
},假);

您在代码中注册了两个事件处理程序,因此在调用
intel.xdk.device.scanBarcode()时会触发这两个事件处理程序您应该有一个事件处理程序,并在事件处理程序中处理以下两种情况:

<script>

var scan = 0; 

function scanNow(){
    scan = 1;
    intel.xdk.device.scanBarcode();
}

function scanNow2(){
    scan = 2;
    intel.xdk.device.scanBarcode();
}

document.addEventListener("intel.xdk.device.barcode.scan",function(ted){
    if (ted.success == true) {
        if(scan == 1){
            scan = 0;
            alert("I'm number 1");
        } else if(scan == 2){
            scan = 0;
            alert("I'm number 2");
        }
    }else{
        alert("ERROR");
    }
},false); 

</script>

var扫描=0;
函数scanNow(){
扫描=1;
intel.xdk.device.scanBarcode();
}
函数scanNow2(){
扫描=2;
intel.xdk.device.scanBarcode();
}
document.addEventListener(“intel.xdk.device.barcode.scan”,函数(ted){
if(ted.success==true){
如果(扫描==1){
扫描=0;
警惕(“我是第一号”);
}否则如果(扫描==2){
扫描=0;
警惕(“我是2号”);
}
}否则{
警报(“错误”);
}
},假);