Javascript Virtualkeyboard

时间:2011-09-09 09:06:14

标签: javascript javascript-events

我正在尝试使用JavaScript制作虚拟键盘。当我要点击密钥时,会创建div,但文本不是来自按键。

alert(targ.childNodes[0].textContent);的帮助下,我能够在警报中显示字符,但是如何将其插入div?

1 个答案:

答案 0 :(得分:0)

如果要在属性中附加String,则onclick函数获取字符串并将该字符串添加到password属性。

function getCharText(text){

    if(capsEnable == 1)
        text = text.toUpperCase();      
    var textString= "";
    var textValue = document.forms[0].password.value;
    if(textValue != '')
            textString = textValue;
    if(document.forms[0].enableKeyboard.checked == true){       
        if(text == "bs" || text == "BS")    
            textString = textString.substring(0, textString.length-1);  
        else if(text == "ca" || text == "CA")   
            textString = "";
        else if(text == "sl" || text == "SL")   
            textString = textString + "\\";
        else if(text == "dq" || text == "DQ")   
            textString = textString + "\"";
        else if(text == "sq" || text == "SQ")   
            textString = textString + "\'";     
        else    
            textString = textString + text ;
    }
    var pwd = document.forms[0].password.value;
    var pwdlen = pwd.length;
    if(pwdlen<15)
    {
        document.forms[0].password.value = textString;
    }
}

试试这个,让我们知道结果......