最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

sweetalert - How to make the confirmation box return true for javascript sweetalert2 - Stack Overflow

programmeradmin7浏览0评论

I want to change my alert box to Sweet Alert2 (/). After clicking the "Ok" button on the Confirm alert window, nothing seems to be happening. I can't seem to figure out what's wrong or how to solve the problem. my codes are as follows:

Html:

<a href="functionalities/removeIning.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'
  )
})
}

I want to change my alert box to Sweet Alert2 (https://sweetalert2.github.io/). After clicking the "Ok" button on the Confirm alert window, nothing seems to be happening. I can't seem to figure out what's wrong or how to solve the problem. my codes are as follows:

Html:

<a href="functionalities/removeIning.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'
  )
})
}
Share Improve this question edited Jan 28, 2018 at 10:41 Limon Monte 54.5k49 gold badges189 silver badges220 bronze badges asked Apr 2, 2017 at 13:11 K.JueK.Jue 411 gold badge2 silver badges8 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4
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'
                    )                
                }
            })      
        }
发布评论

评论列表(0)

  1. 暂无评论