【问题标题】:preventing barcode scanner going to the next input box防止条码扫描器进入下一个输入框
【发布时间】:2018-10-15 14:07:42
【问题描述】:

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

<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; 
              } 
        });     
});

但问题是,一旦它从数据库中搜索值,它就会添加到表中,但是指针会指向下一个输入框,而我没有这样做,因为我需要根据检查不断向表中添加值条码扫描器。我该如何防止呢?

【问题讨论】:

  • > 我如何停止防止这种情况发生?我认为您的意思是如何防止这种情况发生。

标签: javascript php jquery ajax barcode-scanner


【解决方案1】:

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

我用JS禁用了tab键!不记得我是否以某种方式将其限制为文本框中的文本(我想我做到了),但 JS 会是这样的(顺便说一句,这都是凭记忆):

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

如果 keyup 不起作用,它可能是 .change() 或类似的。试试看!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-10
    • 1970-01-01
    • 1970-01-01
    • 2023-01-07
    • 2017-10-29
    • 2014-02-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多