Javascript 删除“;“好的”;“甜蜜警报”对话框中的按钮
我正在使用javascript库 我想从警报框中删除“确定”按钮,但未找到不显示此按钮的任何属性 我正在使用计时器属性Javascript 删除“;“好的”;“甜蜜警报”对话框中的按钮,javascript,jquery,sweetalert,sweetalert2,Javascript,Jquery,Sweetalert,Sweetalert2,我正在使用javascript库 我想从警报框中删除“确定”按钮,但未找到不显示此按钮的任何属性 我正在使用计时器属性timer:1000在一秒钟内关闭警报。 所以,我不认为在这件事上使用ok按钮 尝试将showConfirmButton属性设置为false 您可以使用以下属性: showCancelButton: false, // There won't be any cancel button showConfirmButton: false // There won't be any c
timer:1000
在一秒钟内关闭警报。
所以,我不认为在这件事上使用ok按钮
尝试将
showConfirmButton
属性设置为false
您可以使用以下属性:
showCancelButton: false, // There won't be any cancel button
showConfirmButton: false // There won't be any confirm button
像这样
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')
}
}
)
您需要在配置中设置
showConfirmButton:false
swal({
title: 'Are you sure?',
text: "You won't be able to revert this!",
type: 'warning',
showConfirmButton:false,
confirmButtonText: 'Yes, delete it!'
})
以下是添加任何按钮之前的提示,请清除所有按钮,然后按如下方式重新添加它们(假设警报名称为“A”)- 希望对你有帮助 这对我有用:
$(.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');
});
}
2018年6月4日更新
不再需要showCancelButton和showConfirmButton。相反,您可以设置buttons:true以显示两个按钮,或设置buttons:false以隐藏所有按钮。默认情况下,仅显示确认按钮
所以,现在就不要做了
showCancelButton:false代码>
showConfirmButton:false代码>
照办
按钮:false代码>
使用closeOnClickOutside:false,
它适合我。下面的代码适合我
我只设置了按钮:false代码>
更新
swal({
title: 'Auto close alert!',
text: 'I will close in 2 seconds.',
timer: 2000,
showCancelButton: false,
showConfirmButton: false
});
还有一种方法可以做到这一点
Swal.fire({
键入:“错误”,
标题:“已取消”,
text:“您的报价是安全的此已被接受的答案已被弃用。下面是如何隐藏或删除SweetAlert2中的按钮
{
buttons: false,
}
标题部分:
<link rel="stylesheet" href="https://sweetalert2.github.io/styles/bootstrap4-buttons.css">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script> <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
在配置中设置showConfirmButton:false
!
{
buttons: false,
}
<link rel="stylesheet" href="https://sweetalert2.github.io/styles/bootstrap4-buttons.css">
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script> <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
<a href="" id="delete" class="btn btn-danger">Delete</a>
$(document).on("click", "#delete", function (e) {
e.preventDefault();
var link = $(this).attr("href"); const swalWithBootstrapButtons = swal.mixin({ customClass: {
confirmButton: 'btn btn-success',
cancelButton: 'btn btn-danger' }, buttonsStyling: false }) swalWithBootstrapButtons.fire({ title: 'Are you sure?', text: "You won't be able to revert this!", icon: 'warning', showCancelButton: true, confirmButtonText: 'Yes, delete it!', cancelButtonText: 'No, cancel!', reverseButtons: true }).then((result) => { if (result.isConfirmed) {
swalWithBootstrapButtons.fire(
'Deleted!',
'Your file has been deleted.',
'success'
) } else if (
/* Read more about handling dismissals below */
result.dismiss === swal.DismissReason.cancel ) {
swalWithBootstrapButtons.fire(
'Cancelled',
'Your imaginary file is safe :)',
'error'
) } }) });