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

文章來源:劉俊濤的博客 歡迎關注公衆號、留言、評論,一起學習。


若有幫助到您,歡迎捐贈支持,您的支持是對我堅持最好的肯定(_)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章