我尝试使用Sweet Alert库发出警报。 我试图整合代码来发出删除项目的确认提醒,但是当我点击按钮删除项目时这些不起作用。该对话框不会显示。
代码之前整合Sweet Alert:
$(".delete-link").click(function() {
var id = $(this).attr("id");
var del_id = id;
var parent = $(this).parent("td").parent("tr");
if (confirm('Sure to Delete ID no = ' + del_id)) {
$.post('delete.php', { 'del_id': del_id }, function(data) {
parent.fadeOut('slow');
});
}
return false;
});
在整合Sweet Alert之后代码
。 $(".delete-link").click(function() {
var id = $(this).attr("id");
var del_id = id;
var parent = $(this).parent("td").parent("tr");
});
swal({
title: "Are you sure you want to delete?",
text: "Sure to Delete ID no = " + del_id,
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
closeOnConfirm: false
},
function() {
$.post('delete.php', { 'del_id': del_id }, function(data) {
parent.fadeOut('slow');
});
});
return false;
});
答案 0 :(得分:0)
我认为您的代码中存在语法错误。试试这个,看看它是否有效[我还没有测试过我的代码]。如果它不起作用,请告诉我
$(".delete-link").click(function() {
var id = $(this).attr("id");
var del_id = id;
var parent = $(this).parent("td").parent("tr");
swal({
title: "Are you sure you want to delete?",
text: "Sure to Delete ID no = " + del_id,
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes",
cancelButtonText: "No",
closeOnConfirm: true,
closeOnCancel: true
}, function(isConfirm) {
$.post('delete.php', {'del_id':del_id}, function(data) {
parent.fadeOut('slow');
});
});
return false;
});