Sweetalert: 防止自动关闭甜蜜警报

创建于 2015-05-10  ·  7评论  ·  资料来源: t4t5/sweetalert

尝试做一些简单的事情。 在用户单击确认按钮之前,我不想关闭弹出窗口(我关闭了此选项但弹出窗口仍在关闭)。 这是我的代码:

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(); 
});

如何防止关闭甜蜜警报?

最有用的评论

我知道这已经晚了,但将来可能会帮助某人

@moazam1该选项已更改为

swal({
  closeOnClickOutside: false,
});

https://sweetalert.js.org/docs/#closeonclickoutside

所有7条评论

我似乎也遇到了这个问题。 即使我将 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,
});

https://sweetalert.js.org/docs/#closeonclickoutside

这没有用。

@moazam1谢谢它对我

@moazam1
$(document).on( "click",".fb-share", function(e){
在这里你必须添加 e.preventDefault();
openFbPopup();

它对我有用。
});

此页面是否有帮助?
0 / 5 - 0 等级

相关问题

vmitchell85 picture vmitchell85  ·  6评论

jamieson99 picture jamieson99  ·  3评论

mouro001 picture mouro001  ·  3评论

rapeflower picture rapeflower  ·  4评论

rafatux picture rafatux  ·  5评论