javascript
  • html
  • internet-explorer
  • 2012-06-06 142 views 0 likes 
    0

    我必须实现一个简单的屏幕键盘,用户必须首先单击10个输入框中的一个(使其聚焦),然后使用屏幕键盘将字母添加到聚焦输入。屏幕键盘在Internet Explorer中无法正常工作

    我遇到的问题是,在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'/> 
    

    回答

    0

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

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

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

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

    我意识到这是贴个月前,但它确实帮助了我,我从来没有谢过你。所以那里...非常感谢你。 –

    相关问题