2017-09-05 107 views
0

我正在处理一个小项目,并且在没有结果的长文档之后,我决定寻求一些帮助。 我正在做的是在php和jquery中分配基于条码的系统。 您将在代码中看到的分配过程包括四个扫描,第一次扫描以打开分配会话,第二次扫描订单,第三个扫描位置货架,第四个通过重新扫描订单获取确认窗口(步骤该错误是)。 最后一次扫描应该在打开确认窗口之前模糊窗体的所有输入字段。这会工作一段时间,但随后代码开始将注意力集中在最后选择的输入字段上,通过这个数字搞乱了数字。JQuery试图通过扫描将焦点从文本输入字段中删除

这是具有扫描仪检测功能回调函数的四个步骤,以遵循安全扫描(它被包裹在一个的document.ready功能,我只是没有复制整个代码)

$(document).scannerDetection({ 
    timeBeforeScanTest: 200, // wait for the next character for upto 200ms 
    startChar: [120], // Prefix character for the cabled scanner (OPL6845R) 
    endChar: [13], // be sure the scan is complete if key 13 (enter) is 
    detected 
    avgTimeByChar: 40, // it's not a barcode if a character takes longer than 
    40ms 
    onComplete: function(barcode, qty){ 
    // main callback function 
     console.log(barcode); 
     order=barcode; 
     if($("*:contains('ADD YOUR ORDER')").length>0){ 
      count++; 
      if(count==1){ 
      console.log('First step'); 
      $("#allocation #ordNum").focus(); 
      var lineOrd=$("#allocation #ordNum").closest("tr"); 
      $(lineOrd).addClass("focus"); 

     } 
      if(count==2){ 
      console.log('Second Step'); 
      if($("#allocation #ordNum").val()) { 
      var matchItem=/^\d+$/; 
      ord=$("#allocation #ordNum").val(); 
      if(matchItem.test(ord)===false){ 
       alert("Give a valid order number!"); 
       window.location.href=window.location.href; 
      } 
      $(".focus").removeClass("focus"); 
      $.post("ajax.inc.php", 
      {action:"scanN",order:ord}).done(function(data){ 

      dataa=$(data).text(); 
      if(dataa.indexOf("1.)")>=0){ 
      document.getElementById("soundEffect").play(); 
      alerting=true; 
      alert(dataa); 
      } 
      }); 
      console.log("there is something: "+ord); 
      $("#allocation #location").focus(); 
      var lineLoc=$("#allocation #location").closest("tr"); 
      $(lineLoc).addClass("focus"); 

      }else{ 
      alert('Give a valid ordernumber.'); 
      count--; 
      } 
     } 

       if(count==3){ 
       console.log('Third step'); 
       if($("#allocation #location").val()){ 
        loc=$("#allocation #location").val(); 
        $(":text").blur(); //the line what stops working 
        console.log('location has value'); 
        $("#allocation #update").focus(); 
        //var matchItem2=/^\s?[A-B]\s?[1-6]\s?[A-E]\s?[1-6]\s?$/; 
        var matchItem2=/^\s?[A-B]\s?[1-6]\s?[A-E]\s?[1-6]\s*$/; 
        if(matchItem2.test(loc)===false){ 
        alert("Give a valid location!"); 
        window.location.href=window.location.href; 
        } 

       } 
       } 


       if(count==4){ 
        console.log('Forth step'); 
        $(".focus").removeClass("focus"); 
       if(barcode===ord){ 
        var confi=confirm('Order '+ord+' added to location '+loc); 
        if(confi==true){ 
        $.post("ajax.inc.php", 
    {action:"scan",order:ord,location:loc,thestat:thestat}) 
    .done(function(data){ 
         console.log('Order added'); 
         $(".container").append(data); 
         setTimeout(function(){ 
          window.location.href=window.location.href; 
         },500); 
        //window.location.href=window.location.href; 
        console.log('confirmed'); 
        }); 
       } 
        if(confi==false){ 
        window.location.href=window.location.href; 
        console.log('not confirmed'); 
        } 

       }else{ 
        alert('Allocation is confirmed by rescan of the order'); 
        count--; 
       } 

       } 

    } 


     if($("h2.scan:contains('SCAN TO SEARCH ORDER')").length>0){ 
      $(".container #locations").remove(); 
      $(".container h4#process").remove(); 
      console.log('Scanning Picknote'); 

     $.post("ajax.inc.php{action:"scanN",order:order}).done(function(data) 
     { 
      $(".container").append(data); 
      }); 
     } 
     if($("h2.scan:contains('SCAN TO PROCESS ORDER')").length>0){ 
      console.log('Delete order'); 
      console.log('order:'+order); 
       $.post("ajax.inc.php, 
       {action:"delete",order:order}).done(function(data){ 
        $(".container #processed").append(data); 
        $(".container #locations .forProcess 
       span#"+order).slideUp(); 
       }); 
      } 

      } 
       }); 

任何帮助都可能有帮助。我想实现的目标是,一旦扫描次数达到第3次,就会将注意力集中在表单上的每个输入字段中。即使达到目的,出于某种原因,它会在一段时间后停止执行。 谢谢。

回答

0

请检查这行:

$.post("ajax.inc.php{action:"scanN",order:order}) 

我认为它应该阅读:

$.post("ajax.inc.php",{action:"scanN",order:order}) 
+0

感谢科林的通知,这是复制粘贴错误,昏迷是存在的。我在想这可能是由于警报窗口造成的问题。直到警报窗口具有角色为止。 – domjanzsoo

+0

这是一个很好的观点。警报将把焦点带到提示中的按钮。也许警告后,使用.focus()将焦点设置回输入? – Colin