我可以禁用甜蜜警报js按钮吗?

问题描述 投票:2回答:2

我想禁用甜蜜警报中显示的按钮,这样我的用户就无法一次又一次地点击该按钮。我附上警报here的屏幕截图

我想禁用确认按钮(我不希望关闭警报):

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';
        });
    }
});
javascript jquery sweetalert
2个回答
4
投票

以下是您可以尝试的内容,如果您不想显示任何按钮,也可以添加超时,以便在一段时间后关闭。

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
投票

这对我有用:$(".confirm").attr('disabled', 'disabled');

function DeleteConfirm(c){
  swal({   
            title: "Want to delete this item?",   
            text: "You will not be able to undo this action!",   
            type: "warning",   
            showCancelButton: true,   
            confirmButtonColor: "#DD6B55",   
            confirmButtonText: "Yes, delete it!",   
            closeOnConfirm: false 
        }, function(){ 
          $(".confirm").attr('disabled', 'disabled'); 

        });
}
© www.soinside.com 2019 - 2024. All rights reserved.