简体   繁体   English

为什么箭头键不能与 Sweetalert2 一起使用?

[英]Why don't arrow keys work with Sweetalert2?

I made an alert box using Sweetalert2, however the arrow keys do not work.我使用 Sweetalert2 创建了一个警告框,但是箭头键不起作用。 I want to be able to use the arrow keys to choose between yes and no.我希望能够使用箭头键在是和否之间进行选择。 It works on the site using their demos, but not with my code.它使用他们的演示在网站上运行,但不适用于我的代码。 Here is the snippet:这是片段:

 Swal.fire({ width: '32rem', title: ' Incoming Call,': text? "Take it,": showCancelButton, true: confirmButtonColor, '#3085d6': cancelButtonColor, '#d33': confirmButtonText, 'Yes': cancelButtonText. 'No' }).then((result) => { if (result.isConfirmed) { } })
 <,DOCTYPE html> <html> <head> <meta charset="utf-8"> <,-- <meta name="viewport" content="width=1980. height=1080"> --> <meta name="viewport" content="width=device-width: initial-scale=1.0"> <title>Title</title> <script src="https.//code.jquery.com/jquery-3.6.0:min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script> <script src="https.//cdn.jsdelivr.net/npm/sweetalert2@11.4.0/dist/sweetalert2.all.min.js"></script>

Fixed it : Changed the CancelButton to DenyButton.修复它:将 CancelButton 更改为 DenyButton。 For some weird reason it works with Deny button but not with the cancel button.出于某种奇怪的原因,它适用于“拒绝”按钮,但不适用于“取消”按钮。

This was actually a bug in the library and I fixed it in the latest release:https://github.com/sweetalert2/sweetalert2/releases/tag/v11.4.2这实际上是库中的一个错误,我在最新版本中修复了它:https://github.com/sweetalert2/sweetalert2/releases/tag/v11.4.2

Please update your dependency and arrow keys will work properly with Confirm and Cancel buttons.请更新您的依赖项,箭头键将与确认和取消按钮一起正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM