如果我输入正确的产品代码,则应显示相关详细信息。如果我删除产品代码,则应删除详细信息。我附上下面的屏幕截图。
如果我删除产品代码,仍应显示详细信息。到目前为止我尝试过的东西附在下面。
function getProductcode() {
$("#barcode").empty();
$("#barcode").keyup(function(e) {
var q = $("#barcode").val();
$.ajax({
type: "POST",
url: "get_product.php",
dataType: "JSON",
data: { barcode: $("#barcode").val() },
success: function(data) {
if (data != null) {
is_product = true;
$("#pname").val(data[0].p_name);
$("#pro_price").val(data[0].retail_price);
$("#qty").focus();
$('#barcode').parent('div').removeClass('has-error');
$('#price').html('');
}
else
{
$('#barcode').parent('div').addClass('has-error');
is_product = false;
$("#pname").val('');
$("#pro_price").val('');
$('#qty').val('1');
}
});
}
html
<td>
<div class="focusguard" id="focusguard-1" tabindex="1"></div>
<input type="text" tabindex="2" class="form-control" placeholder="barcode" id="barcode" name="barcode" required>
</td>
<td>
<label id="pro_name" name="pname" id="pname"></label>
<input type="text" class="form-control" placeholder="barcode" id="pname" name="pname" disabled>
</td>
<td>
<input type="text" class="form-control pro_price" id="pro_price" name="pro_price"
placeholder="price" disabled>
</td>
<td>
<input type="number" class="form-control pro_price" id="qty" name="qty"
placeholder="qty" min="1" value="1" required>
</td>
<td>
<input type="text" class="form-control" placeholder="total_cost" id="total_cost" name="total_cost" disabled>
</td>