首页 > 解决方案 > 未从甜蜜警报对话框中删除“确定”按钮

问题描述

由于我在我的项目中使用了甜蜜警报,所以我正在尝试更改按钮文本并添加取消按钮。在某些页面中它可以工作,但在某些页面中它会失败并且只显示OK已修复,这是我下面的屏幕截图。
在职的

它的工作方式与“是”和“取消”按钮一样,但在其他页面中显示如下。

不工作

这是我在下面使用的代码。

function DeleteSubscription(CompanySubscriptionId, CompanyId) {
            swal({
                title: "Are you sure?",
                text: ("You want to delete this Subscription !"),
                type: "warning",
                showCancelButton: true,
                confirmButtonColor: "#5cb85c",
                confirmButtonText: "Yes",
                closeOnConfirm: false
            })
                .then(function (isConfirm) {
                    if (isConfirm) {
                        
                            }
                        });
                    }
                });
        }

与第二张图片一样,它没有将按钮显示为YesCancel only OK

标签: javascriptjquerysweetalertsweetalert2

解决方案


我添加fire到 Swal 中,然后运行它 - 看起来效果很好 - 虽然之前有错误 - 但是你的函数中也必须有很多右括号 -

你没有任何控制台错误吗?

使用 SweetAlert 2

Swal.fire({
                title: "Are you sure?",
                text: ("You want to delete this Subscription !"),
                //type: "warning", -  doesn't exist
                showCancelButton: true,
                 confirmButtonColor: '#d33',
                confirmButtonText: "Yes",
                //closeOnConfirm: false -  doesn't exist
            })
                .then(function (isConfirm) {
                    if (isConfirm) {
                        
                            }
                        });
                    
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9.17.1/dist/sweetalert2.all.min.js"></script>

使用 SweetAlert 1,我添加了解释正在发生的事情的评论

swal({
                    title: "Are you sure?",
                    text: ("You want to delete this Subscription !"),
                    type: "warning", //type and imageUrl have been replaced with a single icon option.
                    icon:'warning', //The right way
                    showCancelButton: true, //showCancelButton and showConfirmButton are no longer needed. Instead, you can set buttons: true to show both buttons, or buttons: false to hide all buttons. By default, only the confirm button is shown.
                    confirmButtonColor: '#d33', //you should specify all stylistic changes through CSS. As a useful shorthand, you can set dangerMode: true to make the confirm button red. Otherwise, you can specify a class in the button object.
                    confirmButtonText: "Yes", // everything is in the buttons argument now
                    closeOnConfirm: false,
                    buttons:true,//The right way
                    buttons: ["No", "Yes"] //The right way to do it in Swal1
                })
                    .then(function (isConfirm) {
                        if (isConfirm) {
                            
                                }
                            });
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>


推荐阅读