繁体   English   中英

防止条形码扫描仪进入下一个输入框

[英]preventing barcode scanner going to the next input box

我试图从数据库中找到一些值,并使用条形码扫描仪使用以下代码将其添加到表中

<div class="form-group m-form__group">
    <label for="exampleInputEmail1">Search by Item name or barcode</label>
    <input type="text"  autofocus class="form-control m-input" id="productSearch"  placeholder="Item ">              
</div>

$( "#productSearch" ).change(function(event) {
    event.preventDefault();
  $.ajax({
          type: "get",
          context: this,
          url: "{!! asset('searchByProductName') !!}",
          dataType: 'json',
          data: { name:this.value },
          success: function(response)
            {
              if ($('#' + response.id).length !== 0)
              { $(this).val("").focus(); return false; }
             var markup = "<tr id="+response.id+"><input type='hidden' name='product_id[]'  value="+response.id+"><td><i class='flaticon-delete-1 delete-row' onclick='deleteRow(this)'></i></td><td>"+response.product_name+"</td><td>"+response.product_unit_price+"</td><td><input type='text' name='quantity[]' class='quantity' value='1'></td><td class='total'>"+response.product_unit_price+"</td><td>"+response.notes+"</td></tr>";

              $("table tbody").append(markup); 


                $(this).val("").focus(); return false; 
              } 
        });     
});

但是问题在于,它一旦从数据库中搜索值,便将其添加到表中,但是指针却指向了下一个输入框,而我并没有这样做,因为我需要根据条形码扫描仪的检查不断向表中添加值。 我该如何预防?

我在比利时电话公司的订阅系统网站上遇到这样的问题,条形码扫描仪的末尾还会包含一个标签!

我用JS禁用了Tab键! 不记得我是否以某种方式将其限制为文本框中的文本(我想是的),但是JS可能是这样的(全部来自内存btw):

$('#some-barcode-input').on('keyup', function(e){ 
    var code = e.keyCode || e.which;
    if(code == 9) { // 9 is the tab key
        return false;
    }
});

如果.change()不起作用,则可能是.change()或类似名称。 试试看!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM