【发布时间】: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