完成登錄與註冊頁面的前端0
阿新 • • 發佈:2017-11-01
ner osi rip orm har flow bsp ots 微軟雅黑
完成登錄與註冊頁面的HTML+CSS+JS,其中的輸入項檢查包括:
用戶名6-12位
首字母不能是數字
只能包含字母和數字
密碼6-12位
註冊頁兩次密碼是否一致
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>歡迎您,請登陸</title> <script type="text/javascript" src="../static/jsp/lx.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> <link rel="stylesheet" href="../static/css/lx.css"> </head> <body> <div class="box"> <h2>登陸</h2> <div class="input_box"> <input id="uname" type="text" name="user" placeholder="請輸入用戶名"> </div> <div class="input_box"> <input id="upass" type="password" name="psw" placeholder="請輸入密碼"> </div> <div id="error_box"><br></div> <div class="input_box"> <button type="button" class="btn btn-primary" onclick="fnLogin()">登陸</button> <a href="regist.html"><input type="button" class="btn btn-info" name="regist" value="註冊"></a> </div> </div> </body> </html>
*{ margin: 0; padding: 0; font-family: 微軟雅黑; font-size: 12px; } .box{ width: 390px; height: 320px; border: solid 1px #ddd; background: #FFF; position: absolute; left: 50%; top:42%; margin-left: -195px; margin-top: -160px; text-align: center; } .box h2{ font-weight: normal; color:#666; font-size: 16px; line-height: 40px; overflow: hidden; text-align: center; border-bottom: solid 1px #ddd; background: #f7f7f7; } .input_box{ width:350px; padding-bottom: 15px; margin: 0 auto; overflow: hidden; }
function fnLogin() { var oUname = document.getElementById("uname") var oUpass = document.getElementById("upass") var oError = document.getElementById("error_box") var isError = true; 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.charCodeAt(i);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 > 20 || oUpass.value.length < 6) { oError.innerHTML = "密碼請輸入6-20位字符" isError = false; return; } window.alert("登錄成功") }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>歡迎您,請登陸</title> <script type="text/javascript" src="../static/jsp/lx.js"></script> <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div id="container" style="width: 400px" align="center"> <div id="header" style="background-color: aquamarine"> <h2 align="center">註冊</h2> </div> <div id="content"> <p align="center">賬號: <input id="uname" type="text" name="user" placeholder="賬號首字符為字母"> </p> <p align="center">密碼: <input id="upass" type="password" name="psw" placeholder="請輸入密碼"> </p> <div id="error_box"><br></div> <br> <button onclick="fnLogin()" class="btn btn-info">註冊</button> </div> <div style="background-color: aquamarine"> <i>版權信息@jk</i> </div> </div> </body> </html>
完成登錄與註冊頁面的前端0