gpt4 book ai didi

javascript - 鼠标点击时 swal

转载 作者:行者123 更新时间:2023-12-01 00:41:11 27 4
gpt4 key购买 nike

以下示例 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");
}
});

另一个示例二来自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'
})

在我的代码库中,如下所示,其行为与示例二相同。单击警报框之外的任意位置时,警报框就会消失。

如何解决这个问题,以便单击警报框之外的任何位置时警报框不会消失?我的 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"
}
});

最佳答案

取决于您使用的 Swal 版本。

对于 SweetAlert 2:

allowOutsideClick: false

对于 SweetAlert(版本 1):

closeOnClickOutside: false 

关于javascript - 鼠标点击时 swal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57700681/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com