完成登录与注册页面的HTML+CSS+JS,其中的输入项检查包括:
用户名6-12位
首字母不能是数字
只能包含字母和数字
密码6-12位
注册页两次密码是否一致
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>欢迎来到登录界面,请登录</title> <script type="text/javascript" src="sdda.js"></script> <link rel="stylesheet" href="sdf.css"> </head> <body> <p id="meto">中国标准时间</p> <script>document.getElementById("meto").innerHTML = Date()</script> <div id="container" style="width: 300px" align="center"> <div id="header" style="background-color: yellow"><h2 align="center">登陆界面</h2></div> <div id="content" style="background-color: aqua"> <p align="center">用户名:<input id="uname" type="text" name="user" placeholder="请输入账号"> </p> <p align="center"> 密码 :<input id="upass" type="password" name="psw" placeholder="请输入密码"></p> <br> <div id="error_box"><br> </div> <input type="radio" value="stu">用户 <input type="radio" value="tea">会员 <br> <input type="checkbox" value="true">记住密码 <a href="">登陆遇到问题</a><br> <button οnclick="fnLogin()">登陆</button>     <input type="button" name="regist" value="注册"> </div> <div id="footer" style="background-color: crimson"><h3 align="center">版权@hir</h3></div> </div> </body> </html>
function fnLogin() { var oUname = document.getElementById("uname") var oUpass = document.getElementById("upass") var oError = document.getElementById("error_box") oError.innerHTML = "<br>" if (oUname.value.length > 20 || oUname.value.length < 6) { oError.innerHTML = "用户名为6-20位字符"; return; } else if(oUname.value.charCodeAt(0)>=48 && oUname.value.charCodeAt(0)<=57){ oError.innerHTML="first letter"; return; }else for(var i=0;i<oUname.value.length; i++){ if((oUname.value.charCodeAt(i)<48 || oUname.value.charCodeAt(i)>57) && (oUname.value.charCodeAt(i)<97 || oUname.value.charCodeAt(i)>122)) oError.innerHTML="only letter or number"; return; } if (oUpass.value.length > 20 || oUpass.value.length < 6) { oError.innerHTML = "密码为 6-20位字符"; return; } window.alert("登陆成功") }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>注册</title> <script src="zhuce.js"></script> </head> <body> <div class="box"> <h1>注册</h1> <div class="input-box"> 账号:<input id="uname" type="text" placeholder="请输入用户名"> </div> <div class="input-box"> 密码:<input id="upass" type="password" placeholder="请输入密码"> </div> <div class="input-box"> 密码:<input id="upass1" type="password" placeholder="请再次输入密码"> </div> <div id="error-box"><br></div> <div class="input-box"> <button οnclick="fnLogin()">确认注册</button> </div> </div> </body> </html>
function fnLogin() { var oUname = document.getElementById("uname"); var oError = document.getElementById("error-box"); var oUpass = document.getElementById("upass"); var oUpass = document.getElementById("upass1") var isoError = true; oError.innerHTML = "<br>"; if (oUname.value.length<6||oUname.value.length>20){ oError.innerHTML="用户名要6-20位"; isoError = false; return; } else if(oUname.value.charCodeAt(0)>=48&&(oUname.value.charCodeAt(0)<=57)){ oError.innerHTML = "用户名首字母必须是字母"; return; } else for(var i=0;i<oUname.value.length;i++){ if((oUname.value.charCodeAt(i)<48||oUname.value.charCodeAt(i)>57)&&(oUname.value.charCodeAt(i)<97||oUname.value.charCodeAt(i)>122)){ oError.innerHTML = "用户名必须为字母或数字"; return; } } if (oUpass.value.length<6||oUpass.value.length>20){ oError.innerHTML="密码至少6-20位"; isoError = false; return; } window.alert("注册成功") }