【发布时间】:2020-04-13 13:15:09
【问题描述】:
我有一个与条形码扫描仪集成的应用程序,如下所示:
我已经用这段代码的 sn-p 动态地做了一行:
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<div class="container" align="top" style="margin-top: 0px;">
<h1 align="center">
Barcode: <br><input type="text" id="myHeader" value="5555">
</h1>
<table id="myTable" class=" table order-list">
<thead>
<tr>
<td>Barcode</td>
<td>Item</td>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
<td colspan="7" style="text-align: left;">
<div align="right">
<p style="color: black;margin-right: 90px;">9.999.999</p>
</div>
<input type="button" class="btn btn-lg btn-block " id="addrow" value="Add Row" style="border-color: black;" />
</td>
</tr>
<tr>
</tr>
</tfoot>
</table>
</div>
这是我用脚本标签包装的代码:
<script >
$(document).ready(function() {
var counter = 0;
$("#addrow").on("click", function() {
var newRow = $("<tr>");
var cols = "";
cols += '<td><input type="text" disabled value="123123123" class="form-control" name="name' + counter + '"/></td>';
cols += '<td><input type="text" disabled value="Sekop" class="form-control" name="mail' + counter + '"/></td>';
cols += '<td><input type="button" class="ibtnDel btn btn-md btn-danger " value="Delete"></td>';
newRow.append(cols);
$("table.order-list").append(newRow);
counter++;
});
$("table.order-list").on("click", ".ibtnDel", function(event) {
$(this).closest("tr").remove();
counter -= 1
});
});
function calculateRow(row) {
var price = +row.find('input[name^="price"]').val();
}
function calculateGrandTotal() {
var grandTotal = 0;
$("table.order-list").find('input[name^="price"]').each(function() {
grandTotal += +$(this).val();
});
$("#grandtotal").text(grandTotal.toFixed(2));
} </script>
但上面的代码只是在我点击Add Row按钮时才添加行。
我现在想要的是,当我用条形码扫描仪扫描条形码时,自动添加的行会跟随扫描的条形码结果。
在这种情况下,它将是:“当标题上的条形码值发生变化时(<h1 align="center">Barcode: 123123123</h1>,当我单击 Add Row 按钮时结果相同。
所以,请参考任何方法、教程或示例代码如何做到这一点,我们将不胜感激:)
更多信息:这个应用程序的目的是为商店的收银员应用程序,例如当收银员扫描产品时,结果会自动出现在应用程序上。我使用 Python Flask 开发它。
【问题讨论】:
-
首先检查条码扫描器启动时的事件。启动时,您需要触发
add row按钮,以便它会在您的表中添加一个新行。之后您可以找到表格的最后一行,然后可以替换Barcode和Item的值。希望它可以帮助您最终确定您的方法。
标签: javascript jquery html barcode barcode-scanner