天天看点

swal 的简单使用例子

swal 的简单使用例子

​swal ​

​询问弹窗

$(".comments .commentDel").on('click',function () {
    swal({
        title: "提示",
        text: "确定要删除该评论吗?",
        icon: "warning",
        buttons: true,
    }).then((y) => {
        if (y) {
            let id=$(this).data('id');
            Ajax('/api/delComment','POST',{id:id},function (res) {
                $("#comment-"+id).prev("hr").remove();
                $("#comment-"+id).remove();
            });
        }
    });
});      

​swal​

​普通弹窗

/**评论*/
$(".comments").on('click',".commentSubmit",function (event) {
    let form=$(this).parents("form");
    if(form[0].checkValidity()==false){
        form.addClass("was-validated");
    }else{
        let data=form.serialize();
        Ajax(comment_url,'post',data,function (res) {
            swal(res.msg, '', "success").then(function () {
                location.reload()
            });
        });
    }
    return false;
});      

你要保守你心,胜过保守一切。

继续阅读