javascript - 防止条码扫描器进入下一个输入框
问题描述
我试图从数据库中找到一些值并使用以下代码使用条形码扫描仪添加到表中
<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 会是这样的(这都是来自内存顺便说一句):
$('#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()
或类似的。试试看!
推荐阅读
- linux - 加载共享库时出错:libreadline.so.7:无法打开共享对象文件:没有这样的文件或目录
- c# - 第一种形式没有消失?
- java - Spring in action 第 5 版 - 第 1 章,STS 设置问题
- go - Goroutine 运行的顺序
- sql - 根据当前表值访问从另一个值中选择值
- c++ - 为什么四核多线程比一核单线程慢
- android - 如何使用 FB NativeAdapter
- python - Tesseract OCR 在 TIFF 文件上失败
- c - BMP 图像,每个像素的位数问题
- ruby-on-rails - Ruby on Rails - 当用户可以是 Task.creator 或 Task.owner 时的 User.tasks