Sweetalert: 转到链接点击确定

创建于 2014-10-28  ·  4评论  ·  资料来源: t4t5/sweetalert

原谅我的经验不足。 我怎样才能做到这一点:

我希望sweetalert 在用户单击链接时显示一条消息,然后只转到链接_if_ 用户在sweetalert 对话框中选择“确定”。

谢谢!

最有用的评论

这实际上很容易实现。 我在这个例子中使用了 jQuery。

$('a').click(function(e){
    e.preventDefault();
    var link = $(this).attr('href');

    swal({
        title: "Are you sure?",
        text: "By clicking 'OK' you will be redirected to the link.",
        type: "warning",
        showCancelButton: true
    },
    function(){
        window.location.href = link;
    });
});

这会将行为添加到所有 a 标记。 如果您只希望它用于某些链接,您可以将特定类添加到 a-tags,并将 sweetAlert 功能限制为它们。

所有4条评论

图书馆没有这样做的选择。 我修改了 #165 中的构造函数(我们需要等待被批准)以向构造函数发送额外的参数,在这种情况下它将是链接。

这实际上很容易实现。 我在这个例子中使用了 jQuery。

$('a').click(function(e){
    e.preventDefault();
    var link = $(this).attr('href');

    swal({
        title: "Are you sure?",
        text: "By clicking 'OK' you will be redirected to the link.",
        type: "warning",
        showCancelButton: true
    },
    function(){
        window.location.href = link;
    });
});

这会将行为添加到所有 a 标记。 如果您只希望它用于某些链接,您可以将特定类添加到 a-tags,并将 sweetAlert 功能限制为它们。

感谢您帮助特里斯坦,这非常有效!

它不工作!

未捕获的 SweetAlert:意外的第二个参数(函数(){
window.location.href = mainURL;

});

我该怎么办?

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

相关问题

xgqfrms-GitHub picture xgqfrms-GitHub  ·  4评论

fracz picture fracz  ·  4评论

blackrosezy picture blackrosezy  ·  6评论

sastrahost picture sastrahost  ·  5评论

rapeflower picture rapeflower  ·  4评论