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

Ank*_*shi 17 javascript jquery sweetalert sweetalert2

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

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

https://github.com/limonte/sweetalert2

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

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

在此输入图像描述

Vip*_*ock 34

您可以使用以下属性:

showCancelButton: false, // There won't be any cancel button
showConfirmButton: false // There won't be any confirm button
Run Code Online (Sandbox Code Playgroud)

像这样

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')
    }
  }
)
Run Code Online (Sandbox Code Playgroud)


New*_*ie 13

更新4/6/2018

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

所以现在而不是做

showCancelButton: false;

showConfirmButton: false;

做就是了

buttons: false;

指南

  • 这是最好的答案! (3认同)

Sau*_*rma 5

您需要showConfirmButton:false在配置中进行设置。

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

这是小提琴