代码之家  ›  专栏  ›  技术社区  ›  caot

鼠标单击时吞咽

  •  0
  • caot  · 技术社区  · 5 年前

    以下内容 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'
    })
    

    在我的代码库中,它的行为与 例二 . 单击警报框外的任何位置时,警报框将消失。

    如何修复它,以便在单击警报框外的任何位置时,警报框不会消失?我的“甜心警报”的版本是什么?

    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 回复  |  直到 5 年前
        1
  •  1
  •   Wilco    5 年前

    取决于您使用的是哪种swel版本。

    对于SweetAlert 2:

    allowOutsideClick: false
    

    closeOnClickOutside: false