【问题标题】:How to make the confirmation box return true for javascript sweetalert2如何使 javascript sweetalert2 的确认框返回 true
【发布时间】:2017-04-02 13:11:17
【问题描述】:

我想将我的警报框更改为 Sweet Alert2 (https://sweetalert2.github.io/)。单击确认警报窗口上的“确定”按钮后,似乎没有任何反应。我似乎无法弄清楚出了什么问题或如何解决问题。我的代码如下:

HTML:

<a href="functionalities/removeIncoming.php?incId=<?php echo $incID; ?>"> 
<button type="button" class="btn btn-default" id="delBtn" onclick="validateRemove(event);">
<span class="glyphicon glyphicon-book" aria-hidden="true"></span>
</button>
</a>

Javascript:

function validateRemove(e) {
    e.preventDefault();
    swal({
  title: "Are you sure you want to archive this entry?",
  type: 'warning',
  showCancelButton: true,
  confirmButtonColor: '#3085d6',
  cancelButtonColor: '#d33',
  confirmButtonText: 'Yes',
  cancelButtonText: "No"
}).then(function () {
  swal(
    'Archived',
    'Your file has been Archived.',
    'success'
  )
})
}

【问题讨论】:

    标签: javascript sweetalert sweetalert2


    【解决方案1】:
    onclick="confirm1();"
    
        function confirm1()
            {
    
                swal({
                    title: 'Are you sure?',
                    text: "You won't be able to revert this!",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'Yes, delete it!',
                    cancelButtonText: 'No, cancel!',
                    confirmButtonClass: 'btn btn-success',
                    cancelButtonClass: 'btn btn-danger',
                    buttonsStyling: false
                }).then(function () {
                    swal(
                      'Deleted!',
                      'Your file has been deleted.',
                      'success'
                    )
                   //success method
                }, function (dismiss) {
                    // dismiss can be 'cancel', 'overlay',
                    // 'close', and 'timer'
                    if (dismiss === 'cancel') {
                        swal(
                          'Cancelled',
                          'Your imaginary file is safe :)',
                          'error'
                        )                
                    }
                })      
            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-06-01
      • 1970-01-01
      • 2019-04-26
      • 1970-01-01
      • 2022-01-06
      • 1970-01-01
      • 2013-01-13
      • 1970-01-01
      相关资源
      最近更新 更多