删除"确定"甜蜜警报对话框中的按钮

时间:2017-02-23 05:49:02

标签: javascript jquery sweetalert sweetalert2

我正在使用javascript sweet alert library:

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

https://github.com/limonte/sweetalert2

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

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

enter image description here

11 个答案:

答案 0 :(得分:25)

您可以使用以下属性:

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

喜欢这个

query string

答案 1 :(得分:13)

更新 4/6/2018

  

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

所以现在不是做

showCancelButton: false;

showConfirmButton: false;

只做

buttons: false;

Guides

答案 2 :(得分: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 :(得分: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'); 

        });
}

答案 4 :(得分:2)

swal({

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

使用closeOnClickOutside: false, 它适用于我。

答案 5 :(得分:0)

尝试将showConfirmButton属性设置为false。

Look at their docs

答案 6 :(得分:0)

下面的代码对我有用

我只设置了buttons: false;

并更新

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

答案 7 :(得分:0)

另一种相同的方法。

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>

答案 8 :(得分:0)

已弃用此接受的答案。这是在SweetAlert2中隐藏或删除按钮的方法。

{
  buttons: false,
}

答案 9 :(得分:0)

标题部分:

<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>

jQuery 部分:

$(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'
    )   } }) });

答案 10 :(得分:-1)

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

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

希望它会有所帮助!!!