我想用着名的甜蜜警报插件在JavaScript上实现confirm()
。但不知何故,甜蜜的警报并没有起作用。
这是我的代码:
function kendaraan(param) {
if (swal({
title: "Are you sure?",
text: "You wanna leave this page?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, Leave!",
closeOnConfirm: false
},
function(){
})
){
switch (param) {
case "ADD_KENDARAAN" :
$.ajax({
type: "POST",
url: "pages/lj_menu/vehicle/add_vehicle.php",
success: function (response, textStatus, jqXHR) {
$('#lj-mainpage').html(response);
}
});
break;
}
}
}
所以我的意图是当用户点击"添加KENDARAAN"时,它应该显示甜蜜的警报确认,当用户点击是然后执行ajax部分。
答案 0 :(得分:0)
不要使用if
,因为它是不必要的。根据文档,只需在switch
anonymous function
内success
实施function kendaraan(param) {
swal({
title: "Are you sure?",
text: "You wanna leave this page?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, Leave!",
closeOnConfirm: false
},
function(){
switch (param) {
case "ADD_KENDARAAN" :
$.ajax({
type: "POST",
url: "pages/lj_menu/vehicle/add_vehicle.php",
success: function (response, textStatus, jqXHR)
{
$('#lj-mainpage').html(response);
swal("Deleted!", "Your imaginary file has been deleted.", "success"); });
//keep success message here if you wish to
}
});
break;
}
});
}
,如下所示:
{{1}}
的 From the DOCS
强>