我有一个sweetalert与2按钮,但我想有一个按钮。例如,到目前为止,我有是和不我想再添加一个按钮说以后。请帮帮我
$("#close_account").on("click", function(e) {
e.preventDefault();
swal({
title: "Are you sure?",
text: "You will not be able to open your account!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, close my account!",
closeOnConfirm: false
},
function() {
window.location.href="<?php echo base_url().'users/close_account' ?>"
});
});
先谢谢你了。
9条答案
按热度按时间b4qexyjb1#
你应该使用定制的HTML与jQuery事件绑定,它的工作原理几乎相同,唯一的问题是,你需要添加自己的按钮样式,因为SweetAlert类不为我工作。
nuypyhwy2#
上面的答案对我不起作用,所以我做了以下几点:
4xrmg8kj3#
🎉🎉🎉 我们最近发布的SweetAlert2 v10支持第三个“deny”按钮:
nbysray54#
Richard Cook在上面评论说,最初的答案(由Konstantin Azizov提供)在SweetAlert 2的4.2.6版本中停止工作。他认为这与添加到html中的节点被克隆有关。我不太了解SweetAlert 2,不知道他是否正确。不过,我可以看到,我的按钮被添加了,但onclick回调函数从未被调用。
通过一点努力,我能够让这个与当前版本的SweetAlert 2一起工作。为了让它工作,我必须在稍后的时间将onclick事件分配给按钮。最后,我给按钮添加了id,使它们更容易从jQuery中选择。然后我将onOpen函数添加到我的swal对象中,并在那里连接逻辑以关联回调函数。下面是一段对我有用的代码。
还要注意,消息和按钮使用了一些现有的SweetAlert 2类,因此它们与现有的UI元素具有相同的外观。提醒一下,我确实尝试过使用swal 2-confirm和swal 2-cancel类。当我这样做的时候,我遇到了一些问题。SweetAlert 2代码可能依赖于仅存在使用该类的单个元素。我没有时间去追踪它,所以我只是停止使用这些类。
t0ybt7op5#
我曾经需要添加第三个按钮到SweetAlert2弹出。在我的例子中,最简单的方法是使用
footer
,它可以是纯文本或HTML:cig3rfwq6#
对于
sweetalert2
,这对我来说很有效:(Run it live)8fq7wneg7#
Sweet Alert在他们的指南页面上有解决方案:https://sweetalert.js.org/guides/#customizing-buttons
在尝试了上述所有解决方案(没有一个成功)后,这个工作得非常好:-)
9njqaruj8#
对于sweetalert2,这对我很有效
kq0g1dla9#
这在ES6中非常容易。
请看这里:如何添加无限按钮
好吧,我可能有点过火了,但你知道它是如何工作的。
为SWAL队加油!这是一个伟大的伟大的产品。