1 回答
TA贡献1828条经验 获得超4个赞
这就是我通常会做的
$(document).ready(function() {
$('[data-click="swal-danger"]').click(function(e) {
e.preventDefault();
var form = $(this).parents('form');
swal({
title: "Are You Sure?",
text: "Are You Sure You Want To Delete.",
icon: "error",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
swal(form.submit(), {
icon: "success",
});
} else {
}
});
});
});
在通过 swal/Sweetalert 提交表单时使用它
swal(form.submit()
然后创建一个表单提交按钮但没有提交类型如下
<form method='post' action='....'>
<button class="btn btn-danger" data-click="swal-danger">DELETE USER</button>
</form>
确保你的按钮上有这个data-click="swal-danger"
添加回答
举报