使用javascript自动更改键盘语言无法使用IE浏览器 [英] auto change keyboard language using javascript not work without IE

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

问题描述

我有一个Java脚本代码,可以在关注文本框时更改键盘语言。但是这段代码只适用于IE,无法在Firefox或Opera中正常工作
我的代码:

i have a Java Script Code that can change Keyboard Language when focus on text box. but this code just work in IE and cant work correctly in Firefox or Opera my code :

<script type="text/javascript"  language="javascript">
var farsi = true ;
var s = new Array(32,33,34,35,36,37,1548,1711,41,40,215,43,
              1608,45,46,47,48,49,50,51,52,53,54,55,56,
              57,58,1603,44,61,46,1567,64,1616,1584,125,
              1609,1615,1609,1604,1570,247,1600,1548,47,
              8217,1583,215,1563,1614,1569,1613,1601,
              8216,123,1611,1618,1573,126,1580,1688,
              1670,94,95,1662,1588,1584,1586,1610,1579,
              1576,1604,1575,1607,1578,1606,1605,1574,
              1583,1582,1581,1590,1602,1587,1601,1593,
              1585,1589,1591,1594,1592,60,124,62,1617);
//==============================================
    function change()
    {

   var KeyID =event.keyCode;
   if(KeyID >= 128)
 {
  alert("تغيير دهيد EN لطفا زبان صفحه کليد را به");
  event.keyCode=0;
  return false;
 }

 if(KeyID > 47 && KeyID < 58) return true;
 if(KeyID < 32)return true;
    if ( KeyID>32 && KeyID<128)  event.keyCode = s[KeyID-32] ;

    }
</script>


推荐答案

此处:

> var KeyID =event.keyCode;

其他浏览器使用 event.which ,所以:

other browsers use event.which, so:

var KeyID = event.which || event.keyCode;

您可以做更多的事情:

var keyProp = typeof event.which == 'number'? 'which' : 'keyCode';

然后:

var keyCode = event[keyProp];



编辑



如果你还在有问题,可能是 W3C DOM Events规范会有所帮助。您可能会注意到事件对象的 keyCode charCode 属性只读,但当然该部分规范是信息性的,而不是规范性的,因此浏览器可能会或可能不会以其他方式表现。

Edit

If you're still having issues, perhaps the W3C DOM Events specification will help. You may note that the keyCode, which and charCode properties of Event objects are readonly, though of course that section of the specification is informational, not normative, so browsers may or may not behave otherwise.

这篇关于使用javascript自动更改键盘语言无法使用IE浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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