删除 table 行并重新索引数字

Deleting table row and re-indexing the numbers

我在删除和重新索引行数方面遇到困难。

例如,数出 7 6 5 4 3 2 1 这样的数字。删除后 3 我要 他们就像 6 5 4 3 2 1。我该怎么做?

function barcodeEntry(barcode) {
  if (barcode.length == 3) {
    var productCount = document.querySelectorAll('.barcodeNumber').length;
    var barcodeTable = document.getElementById("barcode_table");
    
    var rowHtml = "";
    rowHtml = '<tr>';

    if (productCount == 0) {
      rowHtml += '<td class="product-count text-right">' + 1 + '</td>'
    } else {
      productCount++;
      rowHtml += '<td class="product-count text-right">' + productCount + '</td>'
    }
    rowHtml += '<td class="barcodeNumber pl-5" >' + barcode + '</td>'
    rowHtml += '<td class="delete-btn">' + '<a class="mr-2 trash-btn"  >' + 'Delete' + '</a>' + '</td>'
    rowHtml += '</tr>';

    $("#barcode_table").prepend(rowHtml)
    
    $('.trash-btn').on('click', function() {
      $(this).closest("tr").remove();
    })
  }
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.slim.min.js"></script>
<input id="barcodeInput" onkeyup="barcodeEntry(this.value)" />

<table class="w-100">
  <thead>
    <tr class="d-flex justify-content-around">
      <th>
        Count
      </th>
      <th class="pr-5">
        Barcode No
      </th>
      <th></th>
    </tr>
  </thead>
  <tbody id="barcode_table"></tbody>
</table>

jsFiddle link: https://jsfiddle.net/Aycan/8r7xd5us/1/

请使用此代码。

...

$('.trash-btn').on('click', function() {
  $(this).closest("tr").remove();
  const rows = document.querySelectorAll(".product-count");
  [...rows].map((val, index) => {
    val.innerHTML = [...rows].length - index;
  });
})

...