Page is not waiting for response from SweetAlert confirmation window

前端 未结 4 2022
一生所求
一生所求 2021-02-20 11:27

I am trying to upgrade my JavaScript confirm() action to use SweetAlert. Currently my code is something like this:



        
4条回答
  •  说谎
    说谎 (楼主)
    2021-02-20 12:00

    You can do it this way.

    HTML:

    Delete
    

    JS:

    $('.confirmation').click(function (e) {
        var href = $(this).attr('href');
    
        swal({
            title: "Are you sure?",
            type: "warning",
            showCancelButton: true,
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "Yes, delete it!",
            cancelButtonText: "No, cancel plx!",
            closeOnConfirm: true,
            closeOnCancel: true
        },
                function (isConfirm) {
                    if (isConfirm) {
                        window.location.href = href;
                    }
                });
    
        return false;
    });
    

    Seems a hack but it's working for me.

提交回复
热议问题