我正在使用删除电话上的onclick
"<a href='" + Url.Action("Delete", "OBProfile", new { id = "#= ProfileID#" })
+ "' title='Delete' id='deleteButton' class='btn btn-danger btn-sm
deleteButton' onclick='return confirm_delete(#= ProfileID#)'>Delete</a>"
这是它运行的脚本
function confirm_delete() {
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!',
closeOnConfirm: false
},
function () {
swal("Deleted!", "Your imaginary file has been deleted!", "success");
});
};
问题是它没有停止并等待按下删除按钮。它调用脚本,弹出框,删除记录,刷新页面。当我点击确认按钮时,我需要它来处理。这是使用SweetAlert
完成的答案 0 :(得分:0)
因此,无论如何,您必须使用jQuery
才能使swal
正常工作。因此,不要像使用(onclick='return confirm_delete...
)那样使用内联事件处理程序。使用事件绑定jQuery方式,防止默认行为,当确认删除时,将位置设置为转到链接URL,如下所示。
$("#deleteButton").on("click", function(evt) {
evt.preventDefault();
var _this = this;
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!',
closeOnConfirm: false
}, function(isConfirm) {
if (isConfirm) {
swal("Deleted!", "Your imaginary file has been deleted.", "success");
location.href = _this.href;
}
});
});
&#13;
<link href="https://t4t5.github.io/sweetalert/dist/sweetalert.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://t4t5.github.io/sweetalert/dist/sweetalert-dev.js"></script>
<a href='http://www.aol.com' title='Delete' id='deleteButton' class='btn btn-danger btn-sm
deleteButton'>Delete</a>
&#13;