屏幕键盘在 Internet Explorer 中不起作用

OnScreen Keyboard not functioning in Internet Explorer

本文关键字:不起作用 Explorer Internet 键盘 屏幕      更新时间:2023-09-26

我必须实现一个简单的屏幕键盘,用户必须首先单击10个输入框中的一个(以使其聚焦),然后使用屏幕键盘向焦点输入添加字母。

我遇到的问题是,在IE(7,8和9)中,每次字母都会添加到第5个输入框中,无论哪个输入框试图获得焦点。

谁能澄清为什么会发生这种情况?

下面我提供了代码,它在Chrome和Firefox中完美运行。

<img onClick='addIt("q")' src = 'images/alphabet/q.png' style='width:50px;height:50px;cursor:pointer'></div>

单击图像时,它会调用JS函数"addIt('q')",定义如下:

function addIt(key){
  selectedElement = (document.forms["foo"].elements["focusedField"].value!='')?document.forms["foo"].elements["focusedField"].value:"bar";
  d = document.forms["foo"].elements[selectedElement];
  d.value =  d.value + key;
}

focusedField 是在单击输入框时分配的,该输入框是所需功能的密码类型(用户不应看到他正在输入的内容)。

<input type='password' name='4_1' id = '4_1' onFocus='document.forms["foo"].elements["focusedField"].value = this.name'/>

这是因为您使用的字段名称以数字开头。

当您使用 document.forms["foo"].elements["4_1"] 时,Internet Explorer 会将其解释为 document.forms["foo"].elements[4] 并为您提供表单中的第五个元素。

只需使字段名称以字母开头,例如:

<input type='password' name='x4_1' id='x4_1' ...