我在删除记录时有一个用于确认警报的示例脚本。我试图以一些动画的方式做到这一点。但它不能正常工作。这是代码
要删除的按钮的HTML代码
<a href="delete1.php?id=1"><button class="btn btn-danger waves-effect waves-light btn-sm" id="danger-alert">Click me</button> </a>
脚本就像
$('#danger-alert').click(function () {
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "error",
showCancelButton: true,
cancelButtonClass: 'btn-default btn-md waves-effect',
confirmButtonClass: 'btn-danger btn-md waves-effect waves-light',
confirmButtonText: 'Danger!'
});
});
我没有得到我应该将delete1.php文件放在脚本中的位置。
答案 0 :(得分:1)
在回调函数
中使用ajax调用delete1.php
$('#danger-alert').click(function() {
swal({
title: "Are you sure?",
text: "You will not be able to recover this imaginary file!",
type: "error",
showCancelButton: true,
cancelButtonClass: 'btn-default btn-md waves-effect',
confirmButtonClass: 'btn-danger btn-md waves-effect waves-light',
confirmButtonText: 'Danger!',
closeOnConfirm: false,
closeOnCancel: false
}, function(isConfirm) {
if(isConfirm) {
// do ajax
$.ajax({
url: 'delete1.php?id=1',
success: function(response) {
swal("Deleted!", "Your imaginary file has been deleted.", "success");
}
})
}
else {
swal("Cancelled", "Your imaginary file is safe :)", "error");
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="http://t4t5.github.io/sweetalert/dist/sweetalert-dev.js"></script>
<link rel="stylesheet" href="http://t4t5.github.io/sweetalert/dist/sweetalert.css">
<button class="btn btn-danger waves-effect waves-light btn-sm" id="danger-alert">Click me</button>