如何使用sweet alert2确认(然后提交)?

时间:2017-05-22 13:39:10

标签: javascript sweetalert

我有一个按钮,当用户按下时,它显示是或取消如果是按下它将用户重定向到网址这里是我正在使用的代码

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,我想用它来确认或取消

2 个答案:

答案 0 :(得分:0)

从您的问题我想现在您已经添加了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";
  }
  });

答案 1 :(得分:0)

我已经使用过此代码,现在正常工作

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