完成登录与注册页面的前端
完成登录与注册页面的HTML+CSS+JS,其中的输入项检查包括:
用户名6-12位
首字母不能是数字
只能包含字母和数字
密码6-12位
注册页两次密码是否一致
html代码:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>首页</title> <link href="../static/css/111.css"rel="stylesheet" type="text/css"> <script src="../static/js/111.js"></script> </head> <body> <div class="box"> <h2>登录</h2> <div class="input_box"> <input id="uname" type="text" placeholder="请输入用户名"> </div> <div class="input_box"> <input id="upass"type="password"placeholder="请输入密码"> </div> <div id="error_box"><br></div> <div class="input_box"> <button onclick="fnLogin()">登录</button> </div> </div> </body> </html>
css代码:
body{ width: 100px; heigth:100px; margin: 0; background: blanchedalmond; background:rgba(12, 82, 122, 2); } h2{ background: rgba(0,90,120,0.9); color: coral; font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-weight: normal; from-size:2em; padding: 10px 10px 10px 20px; margin-top: 0; margin-bottom: 15px; } .box{ text-align: center; vertical-align: middle; position: absolute; top: 50%; left: 50%; margin: -150px 0 0 -150px; border: 1px solid #ccc; width: 300px; } .input_box{ padding: 5px; min-width: 50%; height: 20px; border-radius: 4px; border: none; font-family: 'Nunito', sans-serif; font-weight: normal; } .button{ text-align: center; display: block; padding: 0; width: 100%; margin-bottom: 10px; color: #fff; font-family: 'Nunito', sans-serif; font-weight: 500; font-size: 0.8em; background: darkgoldenrod; }
js:
function fnLogin () { var oUname = document.getElementById("uname"); var oUpass = document.getElementById("upass"); var oError = document.getElementById("error_box"); var isError = true; oError.innerHTML = "<br>" //uname if (oUname.value.length > 20 || oUname.value.length < 6) { oError.innerHTML = "请输入用户名:6-20位"; isError = false; 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="此用户密码只能包含字母和数字"; return; } } //upass if (oUpass.value.length>20||oUpass.value.length<6){ oError.innerHTML="用户名密码是6-20位"; return } window.alert("登录成功!") }
注册html:
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>注册</title> <link href="../static/css/denglu.css"rel="stylesheet" type="text/css"> <script src="../static/js/111.js"></script> </head> <body> <div class="box"> <h2>注册</h2> <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="phonenumber" type="text"placeholder="请输入手机号"> </div> <div id="error_box"><br></div> <div class="input_box"> <button onclick="fnLogin()">确认注册</button> </div> </div> </body> </html>
css:
h2{ font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-weight: normal; from-size:28px; margin-top: auto; height: 40px; width: 60px; background: aquamarine; } .box{ background: azure; position: absolute; text-align: center; vertical-align: middle; position: absolute; border: 1px solid #ccc; height: 300px; width: 400px; } .input_box{ height: 30px; margin: 5px; text-align: center; } .button{ text-align: center; display: block; width: 100px; height: 40px; margin-rightm: 50px; color: #fff; font-family: 'Nunito', sans-serif; font-size: 16em; background: darkgoldenrod; }
js:
function fnLogin () { var oUname = document.getElementById("uname"); var oUpass = document.getElementById("upass"); var oError = document.getElementById("error_box"); var isError = true; oError.innerHTML = "<br>" //uname if (oUname.value.length > 20 || oUname.value.length < 6) { oError.innerHTML = "请输入用户名:6-20位"; isError = 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; } } //upassword if (oUpass.value.length>20||oUpass.value.length<6){ oError.innerHTML="用户名密码是6-20位"; isError=false; return } window.alert("登录成功!") }