javascript - 未从甜蜜警报对话框中删除“确定”按钮
问题描述
由于我在我的项目中使用了甜蜜警报,所以我正在尝试更改按钮文本并添加取消按钮。在某些页面中它可以工作,但在某些页面中它会失败并且只显示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) {
}
});
}
});
}
与第二张图片一样,它没有将按钮显示为Yes和Cancel only OK。
解决方案
我添加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>
推荐阅读
- python - Gmail 发送的电子邮件提取
- java - 如何将通过spring-boot下拉列表获得的数据保存在数据库中?
- outlook-addin - 发送电子邮件后,ItemId 无效
- java - 如何获取图像内文本的位置并在图像被触摸时突出显示它的位置
- python-3.x - Boto3 generate_presigned_url, SignatureDoesNotMatch 错误
- ruby-on-rails - 打开 Heroku 时出现问题,但网页只是出现“您要查找的页面不存在”的错误。
- python - 如何在退出时阻止多处理发送垃圾邮件?
- c# - 按字符串列表拆分内容
- java - 读取文本文件并制作二维数组
- android - Flutter如何从android studio中的flutter应用程序获取发布版本