简体   繁体   English

未从甜蜜警报对话框中删除“确定”按钮

[英]Not removing “OK” button from sweet alert dialog

As i'm using sweet alert in my project so i'm trying to change button text and add cancel button.由于我在我的项目中使用了甜蜜警报,所以我正在尝试更改按钮文本并添加取消按钮。 In some pages it works but in some it fails and only shows OK fixed, here is my screenshot below.在某些页面中它可以工作,但在某些页面中它会失败并且只显示OK已修复,这是我下面的屏幕截图。
在职的

Its working as seen with Yes and Cancel button but in other page it shows as follows.它的工作方式与“是”和“取消”按钮一样,但在其他页面中显示如下。

不工作

Here is my code which i'm using below.这是我在下面使用的代码。

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

As on the second image its not showing button as Yes and Cancel only OK .与第二张图片一样,它没有将按钮显示为YesCancel only OK

I added fire into Swal, and ran it - Seems like that works fine - It had errors before though - But you have to many closing brackets in your function as well -我在 Swal 中添加了fire ,然后运行它 - 看起来效果很好 - 虽然之前有错误 - 但是你的 function 中也有很多右括号 -

Don't you have any console errors?你没有任何控制台错误吗?

Using SweetAlert 2使用 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>

Using SweetAlert 1, I added comments explaining what is happening使用 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>

Seems like you missing some parameter, check the doc: https://sweetalert2.github.io/#examples好像您缺少一些参数,请查看文档: https://sweetalert2.github.io/#examples

 Swal.fire({ title: "Are you sure?", text: ("You want to delete this Subscription,"): //type, "warning": - doesn't exist showCancelButton, true: showCloseButton, true: // optional showConfirmButton, true: // optional 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM