强制用户在输入文本字段中使用英文键盘输入

发布于 2025-01-05 11:58:36 字数 278 浏览 2 评论 0原文

我有一个输入文本字段,希望用户使用英语键盘而不是阿拉伯语等输入它。 我怎样才能在 HTML 或 Javascript 或 jquery 中做到这一点?

<input type="text" id="username" size="15">

我用这样的 lang 属性测试了它,但它不起作用:

<input type="text" id="username" size="15" lang="en">

i have an input text field and want users type it with English keyboard not with Arabic or etc.
How can i do that in HTML or Javascript or jquery?

<input type="text" id="username" size="15">

i tested it with lang attribute like this,but it didn't work:

<input type="text" id="username" size="15" lang="en">

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

寒冷纷飞旳雪 2025-01-12 11:58:36

纯 javascript 解决方案是:

<script language="JavaScript">
function checkKeycode(e) {
  var keycode=e.keyCode? e.keyCode : e.charCode
  if(isEnglishKeyCode(keycode)){
    //do something if u want
  }
  else{
    void(0);
  }
}
</script>
<form>
<input type="text" onkeydown="checkKeycode(event); this.select()" />
</form>

因此 void(0) “禁用”事件,并且不会将其写入输入中。
我相信你可以编写 isEnglishKeyCode(keycode) 方法。
有关键码的帮助,您可以使用链接或搜索。

Pure javascript solution would be:

<script language="JavaScript">
function checkKeycode(e) {
  var keycode=e.keyCode? e.keyCode : e.charCode
  if(isEnglishKeyCode(keycode)){
    //do something if u want
  }
  else{
    void(0);
  }
}
</script>
<form>
<input type="text" onkeydown="checkKeycode(event); this.select()" />
</form>

So void(0) "disables" the event and it wont be written into the input.
I trust that u can write the isEnglishKeyCode(keycode) method.
For help on keycode u can use this link or search around.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文