JS模拟软键盘

原创 2007年09月23日 11:32:00
 

HTML Tags and JavaScript tutorial



JS模拟软键盘




<script language="javascript">
//more javascript from
http://www.smallrain.net
var oPopUp=null;
function SoftKeyboard(pwdObj){
oPopUp=window.createPopup();
var popBody=oPopUp.document.body;
popBody.style.backgroundColor = "#FFFF99";
popBody.style.border = "solid black 1px";
WriteToPopup(oPopUp,pwdObj);
oPopUp.show(0,22,240,100,pwdObj);
}
function WriteToPopup(oPopUp,pwdObj){
var strHTML="<html><head>";
strHTML+='<meta http-equiv="Content-Type" content="text/html; charset=gb2312">';
strHTML+='<style type="text/css">';
strHTML+='.td{text-align:center; background-color:#FFFF99; vertical-align:middle;font-size:13px;background-Image:(
url:bg.gif
); font-weight:800}';
strHTML+='.button{border:0;width:90%; height:95%;}';
strHTML+='</style>';
strHTML+='<script language="javascript">';
strHTML+='var arrLow=new Array("`","1","2","3","4","5","6","7","8","9","0","-","=","/","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","[","]",";","/'",",",".","/","");';
strHTML+='var arrUp =new Array("~","!","@","#","$","%","^","&","*","(",")","_","+","|","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z","{","}",":","//"","<",">","?",""); ';
strHTML+='var curOverTd=null; var curClkTd=null; var CapsStatus="black";';
strHTML+='var pwdObjectId=parent.document.getElementById("'+pwdObj.id+'");';
strHTML+='function TdMouseOver(TdObj){ ';
strHTML+='TdObj.style.backgroundColor="blue"; ';
strHTML+=' TdObj.style.color="white";';
strHTML+='curOverTd=TdObj;} ';
strHTML+='function TdMouseOut(TdObj){ ';
strHTML+='if(curClkTd==TdObj){ ';
strHTML+='TdObj.style.backgroundColor="red"; ';
strHTML+='TdObj.style.color="white"; ';
strHTML+='}else{ ';
strHTML+='TdObj.style.backgroundColor="#FFFF99"; ';
strHTML+='TdObj.style.color="black"; }';
strHTML+='} ';
strHTML+='function TdMouseClk(TdObj){ ';
strHTML+='if(curClkTd){ ';
strHTML+='curClkTd.style.backgroundColor="#FFFF99"; ';
strHTML+='curClkTd.style.color="black"; }';
strHTML+='TdObj.style.backgroundColor="red"; ';
strHTML+=' TdObj.style.color="white";';
strHTML+='curClkTd=TdObj; ';
strHTML+='curOverTd=null; ';
strHTML+='  pwdObjectId.value+=TdObj.innerText;';
strHTML+=' }';
strHTML+=' function btnCapsDown(btnObj){';
strHTML+='if(CapsStatus=="black"){ CapsStatus="green"; ChgText(arrUp);}';
strHTML+='else{ CapsStatus="black"; ChgText(arrLow);}; ';
strHTML+='btnObj.style.color=CapsStatus=="black"?"#000000":"#33FF66";';
strHTML+=' }';
strHTML+=' function ChgText(arr){';
strHTML+='var table=document.getElementById("tbKeyboard");';
strHTML+='for(var i=0;i<4;i++)';
strHTML+='for(var j=0;j<12;j++)';
strHTML+='table.rows[i].cells[j].innerText=arr[12*i+j];';
strHTML+=' }';
strHTML+=' function btnSpaceDown(){';
strHTML+='pwdObjectId.value+=" "';
strHTML+=' }';
strHTML+=' function btnBackDown(){';
strHTML+='pwdObjectId.value=pwdObjectId.value.substring(0,pwdObjectId.value.length-1)';
strHTML+=' }';
strHTML+=' function btnEnterDown(){';
strHTML+='parent.oPopUp.hide();';
strHTML+=' }';
strHTML+='</scr'+'ipt></head> ';
strHTML+='<body bgcolor="#FFFFFF" style="margin:0; border:0;overflow:hidden;" oncontextmenu="javascript:event.returnValue=false;" onselectstart="javascript:event.returnValue=false;"> ';
strHTML+='<table id="tbKeyboard" cellpadding="0" cellspacing="0" border="1" style="TABLE-LAYOUT: fixed; width:100%;height:100%; border-collapse:collapse; cursor:default" bordercolor="#111111">';
var arr=new Array("`","1","2","3","4","5","6","7","8","9","0","-","=","
//","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","[","]",";","/'",",",".","/
","");
for(var i=0;i<4;i++){
strHTML+='<tr height="12">';
for(var j=0;j<12;j++)
strHTML+='<td class="td" valign="middle" onMouseOver="TdMouseOver(this)" onMouseOut="TdMouseOut(this)" onClick="TdMouseClk(this)">'+arr[i*12+j]+'</td>';
strHTML+='</tr">';
}
strHTML+='<tr height="12"><td class="td" colspan="12"><table width="100%"  border="0" cellpadding="0" cellspacing="0" style="margin:0">';
strHTML+='<tr><td class="td" width="20%" valign="middle"><input type="button" value="Shift" style="font-weight:800 " onclick="btnCapsDown(this)" class="button"></td>';
strHTML+='<td class="td" width="35%" valign="middle"><input type="button" value="Space" onclick="btnSpaceDown()" class="button"></td>';
strHTML+='<td class="td" width="25%" valign="middle"><input type="button" value="Back" onclick="btnBackDown()" class="button"></td>';
strHTML+='<td class="td" width="20%" valign="middle"><input type="button" value="Enter" onclick="btnEnterDown()" class="button"></td>';
strHTML+='</tr></table></td>';
strHTML+='</tr></table></body></html>';
oPopUp.document.write(strHTML);
}
</script>
<input type="text" id="txtPwd" name="txtPwd" onclick="SoftKeyboard(this)" readonly="readonly">
 


相关文章推荐

H5 JS 模拟数字软键盘

  • 2017年07月31日 12:04
  • 2KB
  • 下载

模拟QQ软键盘

  • 2015年06月12日 15:02
  • 157KB
  • 下载

模拟游戏手柄软键盘

package app.mr;// file:JoyStick.javaimport android.content.Context;import android.content.res.Resour...

JS软键盘代码

  • 2015年12月22日 16:38
  • 68KB
  • 下载

JS实现自定义简单网页软键盘效果代码

自写一个简单点的网页软键盘 * { padding:0; margin:0; } body { background:#fff; } th, ...

程序源弃坑之路7(js软键盘)

代码描述了三个text框,前两个是0到9的数字输入,框后有clr清除键,第三个框后有sum按钮可以使前两个数相加。框内禁止键盘输入,在text属性中设置只读。要把输入的数字转化为int的数字不然111...

好用的js 软键盘

  • 2011年12月14日 09:34
  • 426KB
  • 下载
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:JS模拟软键盘
举报原因:
原因补充:

(最多只允许输入30个字)