简体   繁体   English

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

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

I was trying to find some value from database and add to the table using barcode scanner using following code 我试图从数据库中找到一些值,并使用条形码扫描仪使用以下代码将其添加到表中

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

But the problem is as soon as it search the value from the database it adds to the table but the pointer going to next input box which i don't to as i need to continuously add value to the table based on checking from barcode scanner. 但是问题在于,它一旦从数据库中搜索值,便将其添加到表中,但是指针却指向了下一个输入框,而我并没有这样做,因为我需要根据条形码扫描仪的检查不断向表中添加值。 How do i prevent that? 我该如何预防?

I had an issue like this on a Belgian phone companies subscription system website, the barcode scanner would also include a tab at the end of it! 我在比利时电话公司的订阅系统网站上遇到这样的问题,条形码扫描仪的末尾还会包含一个标签!

I used JS to disable the tab key! 我用JS禁用了Tab键! Can't remember if I somehow restricted it to text in the text box or not (I think I did), but the JS would be something like this (this is all from memory btw): 不记得我是否以某种方式将其限制为文本框中的文本(我想是的),但是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;
    }
});

If keyup doesn't work it might be .change() or similar. 如果.change()不起作用,则可能是.change()或类似名称。 Give it a try! 试试看!

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

相关问题 装有条形码扫描仪的输入框 - input box filled with barcode scanner 使用条形码扫描仪将焦点从一个输入更改为另一个输入 - Changing focus from one input to the next with a barcode scanner "检测输入框何时由键盘填充,何时由条形码扫描仪填充。" - Detect when input box filled by keyboard and when by barcode scanner. 条码扫描器输入上的 DOM 重新加载 - DOM Reloads on Barcode Scanner Input Javascript:隐藏输入条码扫描器 - Javascript: Hidden Input Barcode Scanner 只有当用户在输入框上时,条码扫描器才会产生“按键”事件。 当用户不在输入框上时要监听什么事件? - barcode scanner produces a "keypress" event only when the user is on an input box. What event to listen to when user is not on an input box? 条形码扫描仪触发下一个按钮onclick事件和弹出窗口JQuery - Barcode scanner triggers next button onclick event and popup window JQuery 平板电脑Android gt7800集成了扫描仪条码 - 焦点输入 - Tablet Android gt7800 with Scanner Barcode integrated - focus input 从条码扫描器输入JavaScript提取ASCII-30 - Srip ascii-30 from barcode scanner input JavaScript 来自条形码扫描仪的具有多个值的简单 HTML 表单输入字段 - Simple HTML form input field with multiple values from barcode scanner
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM