使用甜蜜警报而不是正常警报()

时间:2018-04-18 19:54:41

标签: javascript jquery ajax

我尝试使用甜蜜警报发出警报当用户点击删除按钮时。

这是我的代码:

$(document).on('click', '.delete', function(){
    var course_id = $(this).attr("id");
    if(confirm("delete ?"))
    {
        $.ajax({
            url:"ajax/delete.php",
            method:"POST",
            data:{user_id,user_id},
            success:function(data)
            {
      swal("done", data, "success");
                dataTable.ajax.reload();
            }
        });
    }
    else
    {
        return false;
    }
});

而不是:

  

如果(确认)

我想用甜蜜的警报。

我试图把swal而不是确认,但它没有工作

我还是初学者:)

谢谢

2 个答案:

答案 0 :(得分:0)

您可以使用与此类似的内容替换确认按钮:

swal("A wild Pikachu appeared! What do you want to do?", {
  buttons: {
    cancel: "Run away!",
    catch: {
      text: "Throw Pokéball!",
      value: "catch",
    },
    defeat: true,
  },
})
.then((value) => {
  switch (value) {

    case "defeat":
      swal("Pikachu fainted! You gained 500 XP!");
      break;

    case "catch":
      swal("Gotcha!", "Pikachu was caught!", "success");
      break;

    default:
      swal("Got away safely!");
  }
});

Scrapoxy documentation

答案 1 :(得分:0)

尝试一下

<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
//.deletebutton is the class name in button
<script>
    $('.deletebutton').on('click', function () {
        // return confirm('Are you sure want to delete?');
        event.preventDefault();//this will hold the url
        swal({
            title: "Are you sure?",
            text: "Once clicked, this will be softdeleted!",
            icon: "warning",
            buttons: true,
            dangerMode: true,
        })
        .then((willDelete) => {
            if (willDelete) {
                swal("Done! category has been softdeleted!", {
                    icon: "success",
                    button: false,
                });
            location.reload(true);//this will release the event
            } else {
                swal("Your imaginary file is safe!");
            }
        });
    });
</script>