js软键盘

javascript
转载他人:效果待定

//定义当前是否大写的状态
var CapsLockValue=0;
var InputControlID = "";
var UILang = "CN";
var old_onscroll_event=null;
var old_onresize_event=null;

function create_keyboard()
{
var div_str = "";

div_str += ('<DIV align="center" id="softkeyboard" name="softkeyboard" style="position:absolute; left:0px; top:0px; width:517px; z-index:180;display:none">');
div_str += ('<FORM name="Calc" action="" method="post" autocomplete="off">');
div_str += ('<INPUT type="hidden" value="ok" name="action2">');
div_str += ('<table width="348" border="0" align="center" cellpadding="3" cellspacing="1" bgcolor="#FF9900">');
div_str += ('<tr>');
div_str += ('<td align="left" bgcolor="#FF9900" align="center">');
div_str += ('<INPUT type="button" value="重新输入" name="reset_input" οnclick="ResetInput()">');
div_str += ('<input name="showCapsLockValue" type="button" onClick="setCapsLock();" value="当前是小写">');
div_str += ('<input type="button" value="关闭" name="close_key" οnclick="closekeyboard();"></td>');

div_str += ('</tr>');
div_str += ('<tr> ');
div_str += ('<td align="center" bgcolor="#FFFFFF" align="center"> <table align="center" width="98%" border="0" cellspacing="0" cellpadding="0">');
div_str += ('<tr align="left" valign="middle">');
div_str += ('<td><input type="button" οnclick="addValue(\'1\');" value=" 1 "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'2\');" value=" 2 "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'3\');" value=" 3 "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'4\');" value=" 4 "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'5\');" value=" 5 "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'6\');" value=" 6 "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'7\');" value=" 7 "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'8\');" value=" 8 "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'9\');" value=" 9 "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'0\');" value=" 0 "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'-\');" value=" - "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'_\');" value=" _ "></td>');
div_str += ('<td colspan=3><input type="button" value="BackSpace" οnclick="setpassvalue();"></td>');
div_str += ('</tr>');
div_str += ('<tr align="left" valign="middle">');
div_str += ('<td><input type="button" οnclick="addValue(\'q\');" value=" q "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'w\');" value=" w "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'e\');" value=" e "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'r\');" value=" r "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'t\');" value=" t "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'y\');" value=" y "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'u\');" value=" u "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'i\');" value=" i "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'o\');" value=" o "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'p\');" value=" p "></td>');
div_str += ('<td><input type="button" onClick="addValue(\':\');" value=" : "></td>');
div_str += ('<td><input type="button" onClick="addValue(\';\');" value=" ; "></td>');
div_str += ('<td><input type="button" onClick="addValue(\'`\');" value=" ` "></td>');
div_str += ('<td colspan=2><input type="button" οnclick="closekeyboard();" value=" Enter"></td>');
div_str += ('</tr>');
div_str += ('<tr align="left" valign="middle">');
div_str += ('<td><input type="button" οnclick="addValue(\'a\');" value=" a "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'s\');" value=" s "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'d\');" value=" d "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'f\');" value=" f "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'g\');" value=" g "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'h\');" value=" h "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'j\');" value=" j "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'k\');" value=" k "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'l\');" value=" l "></td>');
div_str += ('<td><input type="button" onClick="addValue(\'[\');" value=" [ "></td>');
div_str += ('<td><input type="button" onClick="addValue(\']\');" value=" ] "></td>');
div_str += ('<td><input type="button" onClick="addValue(\'{\');" value=" { "></td>');
div_str += ('<td><input type="button" onClick="addValue(\'&\');" value=" & "></td>');
div_str += ('<td><input type="button" onClick="addValue(\'+\');" value=" + "></td>');
div_str += ('<td></td>');
div_str += ('</tr>');
div_str += ('<tr align="left" valign="middle">');
div_str += ('<td><input type="button" οnclick="addValue(\'z\');" value=" z "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'x\');" value=" x "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'c\');" value=" c "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'v\');" value=" v "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'b\');" value=" b "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'n\');" value=" n "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'m\');" value=" m "></td>');
div_str += ('<td><input type="button" onClick="addValue(\'<\');" value=" < "></td>');
div_str += ('<td><input type="button" onClick="addValue(\'>\');" value=" > "></td>');
div_str += ('<td><input type="button" onClick="addValue(\'(\');" value=" ( "></td>');
div_str += ('<td><input type="button" onClick="addValue(\')\');" value=" ) "></td>');
div_str += ('<td><input type="button" onClick="addValue(\'}\');" value=" } "></td>');
div_str += ('<td><input type="button" onClick="addValue(\'\\x27\');" value=" \' "></td>');
div_str += ('<td><input type="button" onClick="addValue(\'\\x22\');" value=\' " \'></td>');
div_str += ('<td></td>');
div_str += ('</tr>');
div_str += ('<tr align="left" valign="middle">');
div_str += ('<td><input type="button" onClick="addValue(\',\');" value=" , "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'~\');" value=" ~ "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'!\');" value=" ! "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'@\');" value=" @ "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'#\');" value=" # "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'$\');" value=" $ "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'%\');" value=" % "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'^\');" value=" ^ "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'*\');" value=" * "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'|\');" value=" | "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'?\');" value=" ? "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'\/\');" value=" \/ "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'\\x5c\');" value=" \\ "></td>');
div_str += ('<td><input type="button" οnclick="addValue(\'.\');" value=" . "></td>');
div_str += ('<td><input type="button" onClick="addValue(\'=\');" value=" = "></td>');
div_str += ('</tr>');
div_str += ('</table></td>');
div_str += ('</tr>');
div_str += ('</table>');
div_str += ('</FORM>');
div_str += ('</DIV>');

document.write(div_str);
}

//给输入的密码框添加新值
function addValue(newValue)
{
var obj = document.getElementById(InputControlID);
if (CapsLockValue==0)
{
obj.value += newValue;
}
else
{
obj.value += newValue.toUpperCase();
}
}
//实现BackSpace键的功能
function setpassvalue()
{
var obj = document.getElementById(InputControlID);
var longnum=obj.value.length;
obj.value=obj.value.substr(0,longnum-1);
}
//
function ResetInput()
{
var obj = document.getElementById(InputControlID);
obj.value="";
}
//关闭软键盘
function closekeyboard()
{
var softkeyboard = document.getElementById("softkeyboard");
softkeyboard.style.display="none";
window.οnscrοll=old_onscroll_event;
window.οnresize=old_onresize_event;
}

//显示软键盘
function showkeyboard(input,lang)
{
InputControlID = input;
if(lang == "EN")
{
document.Calc.reset_input.value="Reset Input";
document.Calc.close_key.value="Close";
document.Calc.showCapsLockValue.value="Lower Case";
UILang = lang;
}
var softkeyboard = document.getElementById("softkeyboard");
softkeyboard.style.display="block";

scroll_keyboard();
scroll_keyboard();

if(window.onscroll != scroll_keyboard)
{
old_onscroll_event = window.onscroll;
}
if(window.onresize != scroll_keyboard)
{
old_onresize_event = window.onresize;
}
window.οnscrοll=scroll_keyboard;
window.οnresize=scroll_keyboard;
}
//设置是否大写的值
function setCapsLock()
{
if (CapsLockValue==0)
{
CapsLockValue=1
if(UILang == "CN")
{
document.Calc.showCapsLockValue.value="当前是大写 ";
}
else
{
document.Calc.showCapsLockValue.value="Upper Case ";
}
}
else
{
CapsLockValue=0
if(UILang == "CN")
{
document.Calc.showCapsLockValue.value="当前是小写 ";
}
else
{
document.Calc.showCapsLockValue.value="Lower Case ";
}
}
}

function scroll_keyboard()
{
var obj = document.getElementById("softkeyboard");
obj.style.top=(document.documentElement.scrollTop+document.documentElement.clientHeight-obj.offsetHeight)+"px";
obj.style.left=(document.documentElement.scrollLeft+document.documentElement.clientWidth-obj.offsetWidth)+"px";
}

create_keyboard();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值