尝试做一些简单的事情。 在用户单击确认按钮之前,我不想关闭弹出窗口(我关闭了此选项但弹出窗口仍在关闭)。 这是我的代码:
sweetAlert({
title: "Hello",
text: "<button type='button' class='btn btn-fb fb-share'>Share on Facebook</button>",
type: null,
confirmButtonText: "Close",
html: true,
closeOnConfirm: false, //It does close the popup when I click on close button
closeOnCancel: false,
allowOutsideClick: false
});
$(document).on( "click",".fb-share", function(e){
//here sweet alert closes when I press this button.
openFbPopup();
});
如何防止关闭甜蜜警报?
我似乎也遇到了这个问题。 即使我将 allowOutsideClick 设置为 false,它仍然是可以关闭的。
@moazam1对于您的特定情况,您需要在 options 对象之后执行回调作为附加参数:
sweetAlert({
title: "Hello",
text: "<button type='button' class='btn btn-fb fb-share'>Share on Facebook</button>",
type: null,
confirmButtonText: "Close",
html: true,
closeOnConfirm: false, //It does close the popup when I click on close button
closeOnCancel: false,
allowOutsideClick: false
}, function () {});
$(document).on( "click",".fb-share", function(e){
//here sweet alert closes when I press this button.
openFbPopup();
});
它不需要做任何事情,而是使用如下函数:
function (isConfirm) {
// ... Rest of code
}
允许您手动响应并执行其他操作。
有道理,就好像您没有处理程序一样,否则您将如何关闭警报。
如果您使用锚标记,只需删除 href="",因为它会将您重定向到同一页面。 这就是警报自行关闭的原因
我知道这已经晚了,但将来可能会帮助某人
@moazam1该选项已更改为
swal({
closeOnClickOutside: false,
});
这没有用。
@moazam1谢谢它对我
@moazam1
$(document).on( "click",".fb-share", function(e){
在这里你必须添加 e.preventDefault();
openFbPopup();
它对我有用。
});
最有用的评论
我知道这已经晚了,但将来可能会帮助某人
@moazam1该选项已更改为
https://sweetalert.js.org/docs/#closeonclickoutside