方式一:
function check(id) {
var serverAddr = 'http://127.0.0.1:8000/app/index.html';
swal({
title: "",
text: "确定删除吗?",
type: "warning",
showCancelButton: "true",
showConfirmButton: "true",
confirmButtonText: "确定",
cancelButtonText: "取消"
}, function () {
var ids = [];
ids.push(id + "");
$.ajax({
type: "post",
url: serverAddr,
traditional: true,
dataType: "json",
data: {"id": ids}
}).done(function (data) {
swal("操作成功!", "已成功删除数据!", "success");
}).error(function (data) {
swal("OMG", "删除操作失败了!", "error");
});
});
}
方式二:
$('button').click(function(){
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "warning",
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: 'Yes, delete it!',
cancelButtonText: "No, cancel plx!",
closeOnConfirm: false,
closeOnCancel: false
},
function(isConfirm){
if (isConfirm){
swal("Deleted!", "Your imaginary file has been deleted!", "success");
} else {
swal("Cancelled", "Your imaginary file is safe :)", "error");
}
});
};
方式三:
<button class="btn btn-danger center" onClick="check({{book.id}})">删除</button>
function check(id){
swal(
{title:"",
text:"",
type:"warning",
showCancelButton:true,
confirmButtonColor:"#DD6B55",
confirmButtonText:"",
cancelButtonText:"",
closeOnConfirm:false,
closeOnCancel:false
},
function(isConfirm)
{
if(isConfirm)
{
swal({title:"删除成功!",
text:"",
type:"success"},function(){window.location=""+id})
}
else{
swal({title:"已取消",
text:"",
type:"error"})
}
}
)
}