求一个网页表单中的虚拟快捷键按钮源码
求一个网页表单中的虚拟快捷键按钮源码
javascript模拟虚拟键盘 网上找的 希望对你有用
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>softkeyboard:code by meixx</title>
<script language="javascript">
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,325,136,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+='.tdnormal{text-align:center; background-image:url(images/bz.GIF); font:13px; color:black; background-repeat:no-repeat; background-position:100% 100%}';
strHTML+='.tdover{text-align:center; background-image:url(images/z.GIF); font:13px; color:black}';
strHTML+='.tdclick{text-align:center; background-image:url(images/zz.GIF); font:13px; color:white}';
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.className ="tdover"; ';
strHTML+=' curOverTd=TdObj;} ';
strHTML+='function TdMouseOut(TdObj){ ';
strHTML+=' if(curClkTd==TdObj)';
strHTML+=' TdObj.className ="tdclick"; ';
strHTML+=' else';
strHTML+=' TdObj.className ="tdnormal"; ';
strHTML+=' } ';
strHTML+='function TdMouseClk(TdObj){ ';
strHTML+=' if(curClkTd)';
strHTML+=' curClkTd.className ="tdnormal"; ';
strHTML+=' TdObj.className ="tdclick"; ';
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+=' if(curClkTd){ if(curClkTd.className=="tdclick") curClkTd.className="tdnormal"; else curClkTd.className="tdclick"; }';
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" oncontextmenu="javascript:event.returnValue=false;" onselectstart="javascript:event.returnValue=false;"> ';
strHTML+='<table id="tbKeyboard" cellpadding="0" cellspacing="0" border="1" bordercolor="#FFFFFF">';
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="27">';
for(var j=0;j<12;j++)
strHTML+='<td class="tdnormal" valign="middle" onMouseOver="TdMouseOver(this)" onMouseOut="TdMouseOut(this)" onClick="TdMouseClk(this)">'+arr[i*12+j]+'</td>';
strHTML+='</tr">';
}
strHTML+='<tr height=""><td class="tdnormal" colspan="12"><table width="100%" border="0" cellpadding="0" cellspacing="0" >';
strHTML+='<tr><td class="tdnormal" width="20%" valign="middle"><input type="button" value="Shift" onclick="btnCapsDown(this)" class="button"></td>';
strHTML+='<td class="tdnormal" width="35%" valign="middle"><input type="button" value="Space" onclick="btnSpaceDown()" class="button"></td>';
strHTML+='<td class="tdnormal" width="25%" valign="middle"><input type="button" value="Back" onclick="btnBackDown()" class="button"></td>';
strHTML+='<td class="tdnormal" 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>
</head>
<body onload="javascript:txtPwd.click()">
<input type="text" id="txtPwd" name="txtPwd" onclick="SoftKeyboard(this)" readonly="readonly">
</body>
</html>