html之SweetAlert2使用方法集锦(一)

方式一:

function check(id) {
            var serverAddr = 'http://127.0.0.1:8000/app/index.html';
            swal({
                title: "",
                text: "确定删除吗?",
                type: "warning",
                showCancelButton: "true",
                showConfirmButton: "true",
                confirmButtonText: "确定",
                cancelButtonText: "取消"
            }, function () {
                var ids = [];
                ids.push(id + "");
                $.ajax({
                    type: "post",
                    url: serverAddr,
                    traditional: true,
                    dataType: "json",
                    data: {"id": ids}
                }).done(function (data) {
                    swal("操作成功!", "已成功删除数据!", "success");
                }).error(function (data) {
                    swal("OMG", "删除操作失败了!", "error");
                });
            });
        }

方式二:

$('button').click(function(){
    swal({
        title: "Are you sure?",
        text: "You will not be able to recover this imaginary file!", 
        type: "warning",
        showCancelButton: true, 
        confirmButtonColor: '#DD6B55', 
        confirmButtonText: 'Yes, delete it!',
        cancelButtonText: "No, cancel plx!", 
        closeOnConfirm: false, 
        closeOnCancel: false  
        //imageUrl: "images/thumbs-up.jpg" 用于替换Title上方的图
    },
    function(isConfirm){
        if (isConfirm){
          swal("Deleted!", "Your imaginary file has been deleted!", "success");
        } else {
          swal("Cancelled", "Your imaginary file is safe :)", "error");
        }
    });
};

方式三:

<button class="btn btn-danger center" onClick="check({{book.id}})">删除</button>  
function check(id){  
            swal(  
                {title:"",  
                text:"",  
                type:"warning",  
                showCancelButton:true,  
                confirmButtonColor:"#DD6B55",  
                confirmButtonText:"",  
                cancelButtonText:"",  
                closeOnConfirm:false,  
                closeOnCancel:false  
                },  
                function(isConfirm)  
                {  
                    if(isConfirm)  
                    {  
                        swal({title:"删除成功!",  
                            text:"",  
                            type:"success"},function(){window.location=""+id})  
                    }  
                    else{  
                        swal({title:"已取消",  
                            text:"",  
                            type:"error"})  
                    }  
                }  
                )  
        }  
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值