原谅我的经验不足。 我怎样才能做到这一点:
我希望sweetalert 在用户单击链接时显示一条消息,然后只转到链接_if_ 用户在sweetalert 对话框中选择“确定”。
谢谢!
图书馆没有这样做的选择。 我修改了 #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;
我该怎么办?
最有用的评论
这实际上很容易实现。 我在这个例子中使用了 jQuery。
这会将行为添加到所有 a 标记。 如果您只希望它用于某些链接,您可以将特定类添加到 a-tags,并将 sweetAlert 功能限制为它们。