<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>qq登录模拟测试</title> </head> <body> <form action="#" method="post"> <input type="text" placeholder="账号" ><br><br> <input type="password" placeholder="密码"> <input type="button" value="点击显示" /> <br><br> <input type="button" value="登录"/> </form> </body> <!--账号密码验证--> <script type="text/javascript"> function check(){ /*非空*/ if(form1.username.value==""){ alert("账号不能为空"); form1.username.focus(); return false; } /*含非数字、首字母为0 /^[0-9]*$/*/ var number=https://www.jb51.net/^(0|[1-9][0-9]*)$/; var objExp1=new RegExp(number); if(objExp1.test(form1.username.value)==false){ alert("账号不能含非数字和首字符为0"); form1.username.focus(); return false; } /*账号小于6位数*/ if(form1.username.value.length < 6){ alert("账号位数过小,请输入6-11位数字"); form1.username.focus(); return false; } /*账号大于11位数*/ if(form1.username.value.length > 11){ alert("账号位数过大,请输入6-11位数字"); form1.username.focus(); return false; } /*密码非空*/ if(form1.password.value==""){ alert("密码不能为空"); form1.password.focus(); return false; } /*密码含有非符号、字母、数字以外字*/ var illegal=https://www.jb51.net/^[0-9a-zA-Z!~@#$%^&*()_+`\-={}:";'<>?,.\/]*$/g; var objExp2=new RegExp(illegal); if(objExp2.test(form1.password.value)==false){ alert("密码含有非法字符"); form1.password.focus(); return false; } /*密码小于6位数*/ if(form1.password.value.length < 6){ alert("密码位数过小,请输入6-16位数字"); form1.password.focus(); return false; } /*密码大于16位数*/ if(form1.password.value.length > 16){ alert("密码位数过大,请输入6-16位数字"); form1.password.focus(); return false; } form1.submit(); } </script> <!--回显密码--> <script type="text/javascript"> window.οnlοad=function(){ var btn=document.getElementById("btn"); var password=document.getElementById("pw") btn.οnmοusedοwn=function(){ password.type="text" }; btn.οnmοuseup=btn.οnmοuseοut=function(){ password.type="password" } } </script> </html>
结果显示: