使用javascript更改键盘布局 [英] change keyboard layout with javascript

查看:91
本文介绍了使用javascript更改键盘布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个html表单.用户可以用英语和波斯语填写表格.但是我有一个验证码输入,用户应该用英语填写.

I have a html form. Users can fill in the form in both english and persian languages. but I have a captcha input that users should fill it in english.

如果用户的键盘布局是波斯语,则在此字段中键入的内容应更改为英语,因此我需要一些编码来更改键盘布局,以专注于此输入文本.

If the user's keyboard layout is persian what is typed in this field should change to english so I need some coded that change the keyboard layout on focusing on this input text.

是否可以使用javascript更改键盘布局?

Is it possbile to change keyboard layout with javascript??

推荐答案

您将无法使用JS更改键盘布局,但是您可以捕获keydown事件并将字符替换为以下内容:

You won't be able to change the keyboard layout using JS, but you can capture the keydown event and replace the character with something like this:

http://jsfiddle.net/SxdKZ/

$('textarea').on('keydown', function(e){

   console.log(e.keyCode); 
    if( e.keyCode == 90 ){
      e.preventDefault();
      $(this).append('y').focus();
    }
    if( e.keyCode == 89 ){
      e.preventDefault();
      $(this).append('z').focus();
    }

});​

这篇关于使用javascript更改键盘布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆