📌  相关文章
📜  jquery 动态行号无法正常工作 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:04:29.083000             🧑  作者: Mango

代码示例1
$(function() {
  function numberRows($t) {
    var c = 0;
    $t.find("tr").each(function(ind, el) {
      $(el).find("td:eq(0)").html(++c + ".");
    });
  }
  $("#add-service-button").click(function(e) {
    e.preventDefault();
    var $row = $("");
    $row.append($(""));
    $row.append($("").html($("#add-service").val()));
    $row.append($("").html("X"));
    $row.appendTo($("#service-table tbody"));
    numberRows($("#service-table"));
  });
  $("#form-entry form").submit(function(e) {
    e.preventDefault();
    $("#add-service-button").trigger("click");
  });
  $("#service-table").on("click", ".del-service", function(e) {
    e.preventDefault();
    var $row = $(this).parent().parent();
    var retResult = confirm("Are you sure you wish to remove this entry?");
    if (retResult) {
      $row.remove();
      numberRows($("#service-table"));
    }
  });
});