我正在尝试在单击表中每行旁边的删除按钮时出现"删除确认模式"。我不确定是我的JavaScript还是HTML的问题。
$("#confirmDelete delete").on("click", function () {
$("#confirmDelete").modal('show');
});
$("delete").on("click", function () {
console.log("Ive been pushed");
var button = $(this);
$.ajax({
url: "/Services/DeleteService/" + button.attr("data-customer-id"),
method: "DELETE",
success: function () {
$(button.parent("tr")).remove();
console.log("Success");
}
});
});
<table id="services" class="table table-bordered table-hover">
@foreach (var service in Model)
{
<tr>
<td>@service.Name</td>
<td><button id="edit" class="btn btn-info edit">Edit</button> <button class="btn btn-danger delete" data-service-id=@service.Id data-target="#confirmDelete"><i class="fa fa-trash-o fa-lg"></i></button></td>
</tr>
}
</table>
第 4 行的 jQuery 选择器正在寻找删除标签而不是删除类 - 它试图找到类似的东西
<delete></delete>
如果要向删除按钮添加单击处理程序,请在选择器之前添加一个".",以告诉jQuery查找具有类"delete"的元素,而不是"delete"类型。例如:
$(".delete").on("click", function () {
"." 将查找具有删除类的元素。
附言您的删除确认按钮将有同样的问题,如果您正在寻找具有"删除"类的按钮。