click()无法在数据表的其他页面

时间:2017-02-08 07:56:00

标签: jquery

我需要从mySQL行中删除用户。我的"删除"按钮仅适用于第一页,但当我更改页面时,它不再有效,as you can see in this image。这是我用于删除的代码:

$(document).ready(function() {
  $('#large').dataTable({
    "sPaginationType": "full_numbers",
    "iDisplayLength": 5,
    "aoColumnDefs": [{
      "bSortable": false,
      "aTargets": [-1]
    }]
  });

  $(".lnk").click(function() {
    if (confirm("This user will be deleted. Press ok to confirm.")) {
      $.ajax({
        type: "POST",
        url: "deactivate-user.php",
        data: {
          "user": $(this).attr('id')
        },
        dataType: 'HTML',
        success: function(data) {
          if (data == "Error") {
            $("#msg").html("Error occured while removing user! Please try after some time.");
            $("#msg").addClass("red-box");
            $("#msg").css("display", "block");
          } else {
            $("#msg").html("User has been removed successfully.");
            $("#msg").addClass("green-box");
            $("#msg").css("display", "block");
            $("#main-table").html(data);
          }
        }
      });
    }
  });
});
<td>
  <a href="add-credit.php?user=<?php echo $row['user_id']; ?>" name="credit" class="btn btn-primary credit">Credit</a>
  <a id="<?php echo $row['user_id']; ?>" class="btn btn-danger lnk">Delete</a>
</td> 

我的错误在哪里?

0 个答案:

没有答案