[英]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.