Javascript 如何使用sweet alert2确认(然后提交)?
我有一个按钮,当用户按下时,它会显示yes或cancel,如果按下yes,它会将用户重定向到url。这是我正在使用的代码Javascript 如何使用sweet alert2确认(然后提交)?,javascript,sweetalert,Javascript,Sweetalert,我有一个按钮,当用户按下时,它会显示yes或cancel,如果按下yes,它会将用户重定向到url。这是我正在使用的代码 if (result.error == 2) { if (confirm(result.message)) { location.href = '/user.php?act=add_booking&id=' + result.goods_id + '&spec=' + result.product_spec; // } } 现在我已经安装
if (result.error == 2)
{
if (confirm(result.message))
{
location.href = '/user.php?act=add_booking&id=' + result.goods_id + '&spec=' + result.product_spec; //
}
}
现在我已经安装了Sweet alert 2,我想用它来确认或取消您的问题,我想现在您已经添加了Sweet alert 2插件。您想更改该插件的代码吗
swal({
title: 'Are you sure?',
text: "You will be redirected!",
type: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes'
},function(isConfirm){
if (isConfirm) {
window.location.href = "http://stackoverflow.com";
}
});
我已经使用了这段代码,它现在运行良好
if (result.error == 2)
{
swal({
title: 'Are you sure?',
text: "Do you want to go to the Log In page?",
type: 'success',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, send me there!'
}, function(){
window.location.href = '/user.php?act=add_booking&id=' + result.goods_id + '&spec=' + result.product_spec;
});
}
您必须包括所需的行为、特定的问题或错误以及在问题本身中重现这些问题所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请参阅:。这是SweetAlert2的示例;您将对顶部的第七个示例最感兴趣。感谢您回答弹出窗口工作正常,但当按下“是”时,它不会重定向,