2017-02-23 106 views
6

我使用的JavaScript甜警报库:删除“OK”甜警告对话框按钮

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

https://github.com/limonte/sweetalert2

我想从警告框去除OK按钮,但我没有找到任何不显示此按钮的属性。

我使用计时器属性timer:1000在一秒钟内关闭警报。 所以,我不认为在这个问题上有一个OK按钮的用法。

enter image description here

+0

集'showConfirmButton:FALSE'在你的配置。 [链接到文档](https://limonte.github.io/sweetalert2/#allow-enter-key) – haxxxton

回答

13

您可以使用这些属性:

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

使用我的应用程序:angular2 + sweetalert2,节省了我的时间! :) – amey

3

你需要设置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

0

添加任何按钮,清除所有的按钮,然后在重新加入他们像(假设警报名称是“A”) -

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

希望它会帮助!

1

这个工作对我来说:$(".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'); 

     }); 
}