【发布时间】:2020-06-25 15:01:03
【问题描述】:
我使用sweet alert 来自定义消息。它工作正常,但现在我需要在用户在页面中的特定上下文上按 Enter 或 Tab 键时显示警报。
为了触发警报,我使用 Jquery 的 keydown 方法。我的问题是,当我通过 Enter 键触发警报时,它会打开,好像用户已经点击了确认按钮。
我知道默认情况下,甜蜜警报与 Enter 键交互,但它不应该等待第二个 Enter 吗?第一个触发警报,然后第二个与警报交互?
就像现在一样,回车键会触发警报并同时进行确认。是否可以更改某些内容以打开警报并使其像往常一样等待?
这是一个小的fiddle,我正在讨论的内容。要查看,请在 enter 和 tab 键之间切换。谢谢。
$(document).keydown(function (e) {
switch (e.which) {
case 13:
case 9:
Swal.fire({
title: 'Are you sure?',
text: "You won't be able to revert this!",
icon: 'warning',
showCancelButton: true,
confirmButtonColor: '#3085d6',
cancelButtonColor: '#d33',
confirmButtonText: 'Yes, delete it!'
}).then((result) => {
if (result.value) {
Swal.fire(
'Deleted!',
'Your file has been deleted.',
'success'
)
}
})
break;
}
});
【问题讨论】:
标签: jquery sweetalert2