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

问题描述 投票:15回答:8

我正在使用javascript甜蜜警报库:

https://limonte.github.io/sweetalert2/

https://github.com/limonte/sweetalert2

我想从警告框中删除“确定”按钮,但我没有找到任何不显示此按钮的属性。

我使用计时器属性timer:1000在一秒钟内关闭警报。所以,我认为在这件事上没有使用ok按钮。

enter image description here

javascript jquery sweetalert sweetalert2
8个回答
25
投票

您可以使用以下属性:

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')
    }
  }
)

13
投票

更新4/6/2018

不再需要showCancelButton和showConfirmButton。相反,您可以设置按钮:true表示按钮或按钮:false表示隐藏所有按钮。默认情况下,仅显示确认按钮。

所以现在而不是做

showCancelButton: false;

showConfirmButton: false;

做就是了

buttons: false;

Guides


4
投票

您需要在配置中设置showConfirmButton:false

swal({
  title: 'Are you sure?',
  text: "You won't be able to revert this!",
  type: 'warning',
  showConfirmButton:false,
  confirmButtonText: 'Yes, delete it!'
})

这是fiddle


3
投票

这对我有用:$(".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'); 

        });
}

2
投票
swal({

    title: "Success",
    text: "Permissions assigned Successfully",
    icon: "success",
    closeOnClickOutside: false,
})

使用closeOnClickOutside: false,它适合我。


0
投票

尝试将showConfirmButton属性设置为false。

Look at their docs


0
投票

下面的代码适合我

我只设置了buttons: false;

并更新

swal({
    title: 'Auto close alert!',
    text: 'I will close in 2 seconds.',
    timer: 2000,
    showCancelButton: false,
    showConfirmButton: false
});

-1
投票

在添加任何按钮之前,清除所有按钮,然后重新添加它们(假设警报名称为'A') -

A.getButtonTypes().clear();
ButtonType OpenStorage=new ButtonType("Open Storage");
A.getButtonTypes().addAll(OpenStorage,ButtonType.CANCEL,ButtonType.NEXT);

希望它会有所帮助!!!

© www.soinside.com 2019 - 2024. All rights reserved.