簡體   English   中英

裝有條形碼掃描儀的輸入框

[英]input box filled with barcode scanner

我有可以從條形碼掃描儀輸入中填寫的輸入框。

 <input type="text"  autofocus class="form-control m-input" id="productSearch" aria-describedby="emailHelp" placeholder="Product name">   

但是問題是,每當輸入框充滿輸入時,它應該為空並將相關值添加到表中。 我已經使用以下功能來做到這一點。 相關值會自動添加到表中,但問題在於它還會顯示自動提示。 我如何停止顯示自動提示以及將值設為空。

$("#productSearch").keypress(function(event) {
  if (event.which == '10' || event.which == '13') {
    // alert(this.value)
    $.ajax({
      type: "get",
      url: "{!! asset('searchByProductName') !!}",
      dataType: 'json',
      data: {
        name: this.value
      },
      success: function(response) {
        // console.log(response)
        if ($('#' + response.id).length !== 0)
          return;

        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);
        calculateSum();

        $('.quantity').on('keyup', function() {
          var currentRow = $(this).closest("tr");
          var col3 = currentRow.find("td:eq(2)").text();
          var data = col3 * $(this).val();
          currentRow.find("td:eq(4)").text(data.toFixed(2))
          calculateSum();
        });

        $(this).val("");
        return false;
      }
    });
    event.preventDefault();
  }
});

這里提一下。 如果條形碼掃描儀找不到價值,我也使用上述輸入框實施了自動提示。

條形碼掃描儀的工作原理類似於鍵盤。 它是文本輸入設備。 將函數寫入文本框的文本更改事件。 檢查字符串的長度,然后調用一個函數以將字符串添加到數據庫並清除文本字段。 希望這可以幫助。

關閉自動完成

<input type="text"  autofocus class="form-control m-input" id="productSearch" aria-describedby="emailHelp" placeholder="Product name" autocomplete="off"> 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM