Javascript 从甜蜜警报对话框中删除“确定”按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42408044/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Remove "OK" button from sweet alert dialog
提问by Ankush Rishi
I am using javascript sweetalert2library.
我正在使用 javascript sweetalert2库。
I want to remove the OK button from the alert box but I did not find any property for not to display this button.
我想从警告框中删除 OK 按钮,但我没有找到任何不显示此按钮的属性。
I am using the timer property timer:1000for closing the alert in one second.
So, I don't think there is a use of the ok button in this matter.
我正在使用 timer 属性timer:1000在一秒钟内关闭警报。所以,我认为在这件事上没有使用 ok 按钮。
回答by Viplock
You can use these properties:
您可以使用这些属性:
showCancelButton: false, // There won't be any cancel button
showConfirmButton: false // There won't be any confirm button
Like This
像这样
swal({
title: 'Auto close alert!',
text: 'I will close in 2 seconds.',
timer: 2000,
showCancelButton: false,
showConfirmButton: false
}).then(
function () {},
// handling the promise rejection
function (dismiss) {
if (dismiss === 'timer') {
//console.log('I was closed by the timer')
}
}
)
回答by NewBie
Update 4/6/2018
2018 年 4 月 6 日更新
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.
不再需要 showCancelButton 和 showConfirmButton。相反,您可以设置 buttons: true 以显示两个按钮,或设置 buttons: false 以隐藏所有按钮。默认情况下,仅显示确认按钮。
So now instead of doing
所以现在而不是做
showCancelButton: false;
showCancelButton: false;
showConfirmButton: false;
showConfirmButton: false;
Just do
做就是了
buttons: false;
buttons: false;
回答by Saurabh Sharma
回答by Salah
This works for me: $(".confirm").attr('disabled', 'disabled');
这对我有用: $(".confirm").attr('disabled', 'disabled');
My function:
我的功能:
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');
});
}
回答by Toqeer Chaudhary
swal({
title: "Success",
text: "Permissions assigned Successfully",
icon: "success",
closeOnClickOutside: false,
})
Use closeOnClickOutside: false,It works for me.
使用 closeOnClickOutside: false,它对我有用。
回答by Suhas Bachhav
Below code works for me
下面的代码对我有用
I have only set buttons: false;
我只设置了 buttons: false;
and update
并更新
swal({
title: 'Auto close alert!',
text: 'I will close in 2 seconds.',
timer: 2000,
showCancelButton: false,
showConfirmButton: false
});
回答by Penny Liu
One more way to do the same.
另一种方法来做同样的事情。
Swal.fire({
type: 'error',
title: 'Cancelled',
text: 'Your offer is safe ',
showConfirmButton: false,
timer: 2000
})
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@8"></script>
Upgrading to v9.xof SweetAlert2.
升级到v9.xSweetAlert2。
Breaking change- rename
typetoicon
重大更改- 重命名
type为icon
Swal.fire({
icon: 'error',
title: 'Cancelled',
text: 'Your offer is safe ',
showConfirmButton: false,
timer: 2000
})
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>
回答by kaleazy
This accepted answer has been deprecated. Here is how you can hide or remove buttons in SweetAlert2.
此已接受的答案已被弃用。以下是在 SweetAlert2 中隐藏或删除按钮的方法。
{
buttons: false,
}
回答by the_lost_one
Try setting the showConfirmButtonproperty to false.
尝试将该showConfirmButton属性设置为 false。
回答by Ragib
Before adding any buttons,clear all the buttons and then re-add them like(assuming the Alert name is 'A') -
在添加任何按钮之前,清除所有按钮,然后重新添加它们(假设警报名称为“A”) -
A.getButtonTypes().clear();
ButtonType OpenStorage=new ButtonType("Open Storage");
A.getButtonTypes().addAll(OpenStorage,ButtonType.CANCEL,ButtonType.NEXT);
Hope it'll help!!!
希望能帮到你!!!


