我正在做一个学校项目,我无法使用sweetalert进行删除确认。
这是脚本:
<script type="text/javascript">
function myDelete {
e.preventDefault();
swal({
title: "Are you sure?",
text: "You want to Save this project?",
type: "warning",
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: 'Yes, I am sure!',
cancelButtonText: "No, cancel it!",
closeOnConfirm: true,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm) {
return true;
// $(this).trigger('click');
$('#LinkButton1').click();
// e.currentTarget.submit();
} else {
return false;
// alert("False");
}
});
</script>
我想做的是,当我单击网格视图上的链接按钮时,它显示出甜蜜的确认,询问我是否要删除!
这是我的链接按钮:
<asp:LinkButton ID="LinkButton1" CssClass="delete" runat="server" OnClientClick="return Confirm(this, event);" CommandName="Delete">LinkButton</asp:LinkButton>
请,我真的需要帮助! 谢谢。
答案 0 :(得分:0)
您的asp链接按钮将调用确认功能。如果“是,我确定!”,确认将返回true。被按下
使用sweetalert@2.1.2
function confirm(button, e) {
e.preventDefault();
var buttonId = $(button).attr('id');
console.log(buttonId);
swal({
title: "Are you sure?",
text: "You want to Save this project?",
type: "warning",
buttons: ["No, cancel it!", "Yes, I am sure!"],
}).then((confirm) => {
if (confirm) {
console.log("confirm:", confirm);
return true;
} else {
console.log("confirm:", confirm);
return false;
}
});
}
JsFiddle:https://jsfiddle.net/167a4z8k/3/