我需要使用 jquery 在英语键盘布局和日语键盘布局之间给出条件

I need to give condition between english keyboard layout and japanese keyboard layout using jquery

提问人:Karthi A 提问时间:10/3/2023 最后编辑:freedomn-mKarthi A 更新时间:10/3/2023 访问量:16

问:

以下代码条件是日语键盘键码,如果我更改英语键盘布局,它需要工作。

$('input,textarea,div#editorId').on('keydown', function(e) {
  if ((e.shiftKey == false && e.keyCode == 220) || (e.shiftKey == false && e.keyCode == 226)) {
    Swal.fire({
      type: "info",
      html: "BackSlash is not allowed",
      confirmButtonClass: "btn btn-success"
    })
  } else if ((e.shiftKey == true && e.keyCode == 192) || (e.shiftKey == true && e.keyCode == 50) || (e.shiftKey == true && e.keyCode == 55)) {
    Swal.fire({
      type: "info",
      html: "Double and Single Quotes are not allowed",
      confirmButtonClass: "btn btn-success"
    })

  } else if (e.shiftKey == false && e.keyCode == 188) {
    Swal.fire({
      type: "info",
      html: "Comma is not allowed",
      confirmButtonClass: "btn btn-success"
    })
  }
});
jQuery 符号 CJK 键码

评论

0赞 freedomn-m 10/3/2023
您应该考虑使用和检查整个输入,而不是单个按键。否则,用户只能粘贴不允许的字符。如果执行此操作,请务必保留用户的克拉位置。input
0赞 freedomn-m 10/3/2023
另请注意:没有“英文布局” - 有不同的布局,例如 Qwerty 和 Dvorak(尽管我不能说它们是否都使用相同的 keyCode) - 所以检查字符而不是 keyCode - keyCode 对非字符很有用,例如箭头键。

答: 暂无答案