In view of security considerations, many websites use soft keyboards when logging in and entering passwords to avoid keystroke capture by some keylogging tools and Trojans. There is also this requirement in the project, so I will share it with everyone and post a rendering. . Interested friends can collect it. . .. If you think the function is a bit too large and only need a numeric keypad, you can refer to the code simplification. Download large keyboard: http://www.cnblogs.com/Files/sccxszy/softKey.rar Small keyboard: http://www.cnblogs.com/Files /sccxszy/smallSoftkey.rar
Small keyboard:
Effect restoration: Three files: Default.aspx, softkeyboard.js, softkey.css js code: softkeyboard.js
function addValue(newValue) { if (CapsLockValue==) { var str=Calc.password.value; if(str.length{ Calc.password.value = newValue; } if(str.length{ password.value=Calc.password.value; } } else { var str=Calc.password.value; if(str.length{ //Calc.password.value = newValue.toUpperCase(); Calc.password.value = newValue; } if(str.length{ password.value=Calc.password.value; } } }
function setpassvalue() { var longnum=Calc.password.value.length; var num num=Calc.password.value.substr(,longnum-); Calc.password.value=num; var str=Calc.password.value; password.value=Calc.password.value; }
function OverInput() { var str=Calc.password.value; password.value=Calc.password.value; closekeyboard(); Calc.password.value=""; password.readOnly=; }
function closekeyboard(theForm) { softkeyboard.style.display="none"; if(null!=unhideSelect){ unhideSelect(); } }
function showkeyboard() { randomNumberButton(); var th = password; var ttop = th.offsetTop; var thei = th.clientHeight; var tleft = th.offsetLeft; var ttyp = th.type; while (th = th.offsetParent){ttop =th.offsetTop; tleft =th.offsetLeft;} softkeyboard.style.top = ttop thei ; softkeyboard.style.left = tleft-; softkeyboard.style.display="block"; password.readOnly=; password.blur(); document.all.useKey.focus(); if(null!=hideSelect){ hideSelect(); } }
function setCapsLock() { if (CapsLockValue==) { CapsLockValue= } else { CapsLockValue= } } function setCalcborder() { CalcTable.style.border="px solid #BADF" } function setHead() { CalcTable.cells[].style.backgroundColor="#BADF" } function setCalcButtonBg() { for(var i=;i{ if(Calc.elements[i].type=="button"&&Calc.elements[i].bgtype!="") { if(Calc.elements[i].bgtype==""){ Calc.elements[i].className="btn_num"; }else{ Calc.elements[i].className="btn_letter"; } var str=Calc.elements[i].value; str=str.trim(); if(str.length==) { } var thisButtonValue=Calc.elements[i].value; thisButtonValue=thisButtonValue.trim(); if(thisButtonValue.length==) { Calc.elements[i].onclick= function () { var thisButtonValue=this.value; thisButtonValue=thisButtonValue.trim(); thisButtonValue=jiamiMimaKey(thisButtonValue); addValue(thisButtonValue); } Calc.elements[i].ondblclick= function () { var thisButtonValue=this.value; thisButtonValue=thisButtonValue.trim(); thisButtonValue=jiamiMimaKey(thisButtonValue); addValue(thisButtonValue); } } } } } function initCalc() { setCalcborder(); setHead(); setCalcButtonBg(); } String.prototype.trim = function() { return this.replace(/(^s*)|(s*$)/g, ""); } var capsLockFlag; capsLockFlag=true; function capsLockText() { if(capsLockFlag) { for(var i=;i{ var char=Calc.elements[i].value; var char=char.trim() if(Calc.elements[i].type=="button"&&char>="a"&&char{ Calc.elements[i].value=" " String.fromCharCode(char.charCodeAt()-) " " } } } else { for(var i=;i{ var char=Calc.elements[i].value; var char=char.trim() if(Calc.elements[i].type=="button"&&char>="A"&&char{ Calc.elements[i].value=" " String.fromCharCode(char.charCodeAt() ) " " } } } capsLockFlag=!capsLockFlag; }
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn