鼠标点击

时间:2019-08-28 22:15:01

标签: javascript jquery html sweetalert

以下example ONE来自https://lipis.github.io/bootstrap-sweetalert/。单击警报框外的任何位置时,警报框都不会消失。这就是我所期望的。

swal({
  title: "Are you sure?",
  text: "You will not be able to recover this imaginary file!",
  type: "warning",
  showCancelButton: true,
  confirmButtonClass: "btn-danger",
  confirmButtonText: "Yes, delete it!",
  cancelButtonText: "No, cancel plx!",
  closeOnConfirm: false,
  closeOnCancel: false
},
function(isConfirm) {
  if (isConfirm) {
    swal("Deleted!", "Your imaginary file has been deleted.", "success");
  } else {
    swal("Cancelled", "Your imaginary file is safe :)", "error");
  }
});

另一个example TWO来自https://sweetalert2.github.io/。它以另一种方式表现。单击警报框外的任何位置时,警报框都消失了。

Swal.fire({
  title: '<strong>HTML <u>example</u></strong>',
  type: 'info',
  html:
    'You can use <b>bold text</b>, ' +
    '<a href="//sweetalert2.github.io">links</a> ' +
    'and other HTML tags',
  showCloseButton: true,
  showCancelButton: true,
  focusConfirm: false,
  confirmButtonText:
    '<i class="fa fa-thumbs-up"></i> Great!',
  confirmButtonAriaLabel: 'Thumbs up, great!',
  cancelButtonText:
    '<i class="fa fa-thumbs-down"></i>',
  cancelButtonAriaLabel: 'Thumbs down'
})

在我的代码库中,其行为与example TWO相同。单击警报框以外的任何位置时,警报框都不见了。

如何解决该问题,以便在单击警报框之外的任何位置时,警报框不会消失?我的sweetalert的版本可能是什么?

swal({
    title: "Message:",
    text: "Here is some detailed message",
    type: "warning",
    buttons: {
        to_refresh: {
            text: "Refresh the current view",
            visible: true,
            closeModal: true
        },
        to_close: {
            text: "Back to Main Menu!",
            visible: true,
            closeModal: true
        },
    },
}).then(value => {
    if (value === 'to_refresh') {
        // window.location.href = window.location.href;
        location.reload(true);
    } else {
        window.location.href = "to some other link"
    }
});

1 个答案:

答案 0 :(得分:2)

,取决于您使用的Swal版本。

对于SweetAlert 2:

allowOutsideClick: false

对于SweetAlert(版本1):

closeOnClickOutside: false