最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Can I disable sweet alert js buttons? - Stack Overflow

programmeradmin1浏览0评论

I want to disable the button displayed in sweet alerts so that my user cannot click the button again and again. I have attached the screen shot of the alert here

I want to disable the confirmation button (I don't want the alert to be closed):

swal({
    title: "Are you sure?",
    text: "You want to add this discount?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "Continue",
    cancelButtonText: "Cancel",
    closeOnConfirm: false,
    closeOnCancel: false
}, function (isConfirm) {
    if (isConfirm) {
        document.getElementById('message_error_new_discount').innerHTML = '';
        $.post('./CURL/addNewDiscount.php', JSON.stringify({
            "code": discount_code_newDiscount,
            "percentage": percentage_newDiscount,
            "startDate": sdate_newDiscount,
            "endDate": edate_newDiscount
        }), function (data) {
            var text = "your discount code is " + data.code;
            swal({ title: "Discount Added!", text: text, type: "success" }, function () {
                window.location = './discountlist.php';
            });
        });
    } else {
        swal({ title: "Cancelled", text: "", type: "error" }, function () {
            window.location = './discountlist.php';
        });
    }
});

I want to disable the button displayed in sweet alerts so that my user cannot click the button again and again. I have attached the screen shot of the alert here

I want to disable the confirmation button (I don't want the alert to be closed):

swal({
    title: "Are you sure?",
    text: "You want to add this discount?",
    type: "warning",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "Continue",
    cancelButtonText: "Cancel",
    closeOnConfirm: false,
    closeOnCancel: false
}, function (isConfirm) {
    if (isConfirm) {
        document.getElementById('message_error_new_discount').innerHTML = '';
        $.post('./CURL/addNewDiscount.php', JSON.stringify({
            "code": discount_code_newDiscount,
            "percentage": percentage_newDiscount,
            "startDate": sdate_newDiscount,
            "endDate": edate_newDiscount
        }), function (data) {
            var text = "your discount code is " + data.code;
            swal({ title: "Discount Added!", text: text, type: "success" }, function () {
                window.location = './discountlist.php';
            });
        });
    } else {
        swal({ title: "Cancelled", text: "", type: "error" }, function () {
            window.location = './discountlist.php';
        });
    }
});
Share Improve this question edited Jun 2, 2016 at 11:32 CozyAzure 8,4787 gold badges38 silver badges55 bronze badges asked Jun 2, 2016 at 11:06 Thishani LucasThishani Lucas 5801 gold badge4 silver badges21 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Here is what you can try, if you don't want to show any button and also you can add timeout, so that it will be closed after sometime.

swal({   
    title: "Are you sure?",   
    text: "You want to add this discount?",   
    type: "warning",   
    showCancelButton: true,   
    confirmButtonColor: "#DD6B55", 
    confirmButtonText: "Continue",   
    cancelButtonText: "Cancel",   
    closeOnConfirm: false,   
    closeOnCancel: false 
}, function(isConfirm){   
    if (isConfirm) {
        document.getElementById('message_error_new_discount').innerHTML = '';
        $.post('./CURL/addNewDiscount.php',JSON.stringify({
            "code": discount_code_newDiscount,
            "percentage": percentage_newDiscount,
            "startDate": sdate_newDiscount,
            "endDate": edate_newDiscount
            }),function(data){
                var text = "your discount code is "+data.code;
                swal({title:"Discount Added!",
                      text:text, 
                      type:"success",
                      showCancelButton: false,//There won't be any cancle button
                      showConfirmButton  : false //There won't be any confirm button
                     },function(){
                    window.location='./discountlist.php';
                });
        });
    }else{
        swal({title:"Cancelled",text:"", type:"error"},function(){
            window.location='./discountlist.php';
        });
    }
});
发布评论

评论列表(0)

  1. 暂无评论