我正在开展一个学校项目,我无法使用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>
而我想要做的是当我点击我的gridview上的链接按钮时,它会显示sweetalert确认,询问我是否要删除或不!
这是我的链接按钮:
<asp:LinkButton ID="LinkButton1" CssClass="delete" runat="server" OnClientClick="return Confirm(this, event);" CommandName="Delete">LinkButton</asp:LinkButton>
拜托,我真的需要帮助!谢谢。
您的asp链接按钮将调用确认功能。如果“是的,我确定!”确认将返回true。被压了
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/