我用append()
方法追加数据,我用remove()
删除每个元素。但是,我无法删除列表中的最后一个元素。无法删除Jquery中最后添加的元素
$(document).ready(function() {
$(".add_cart").click(function() {
var id = this.id;
$(this).prop("disabled", true);
$(this).val("Item Already in Cart");
$.get("cart.php", {
"id": id
}, function (data) {
$("#sam").append("<table class='tables'><tr><td>" + data + "</td><td><input class='remove' id='" + id + "' type='button' value='Remove'></td></tr></table>");
});
$(".tables").click(function() {
$(this).remove()
});
});
});
其中'删除()'一部分? –
也许你可以使用'$(this).html('');'替换你表中的内容。 –
现在我编辑了删除部分 – Venktesh