WebApp之H5登录注册
代码indexhtml
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>TencentQQ</title> <meta name="viewport" content="width=device-width,initial-scale=1"> <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.css" /> <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> <script src="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.min.js"></script> <script type="text/javascript" src="js/index.js" ></script> </head> <body> <!--登陆页面--> <div data-role="page" id="pageLogin"> <div data-role="header"> <h1 role="heading">Tencent办公系统</h1> </div> <div data-role="main" class="ui-content"> <form method="get" action=""> <div class="ui-field-contain"> <label for="name">帐号:</label> <input type="text" name="u_name" id="u_name"> <br/> <label for="password">密码:</label> <input type="password" name="u_password" id="u_password"> <div style="margin-top: 20%;"> <input type="button" value="登录" onclick="login()" /> <a href="#pagetwo" data-role="button" data-transition="flip">注册</a> </div> <h5 style="color: red;">测试登录帐号:admin 密码:admin888</h5> <h5 style="color: red;">测试登录帐号:root 密码:123456</h5> </div> </form> </div> <div data-role="footer" style="text-align: center" data-position="fixed"> <p>Copyright © 1998 - 2017 Tencent</p> </div> </div> <!--注册页面--> <div data-role="page" id="pagetwo" data-theme="b"> <div data-role="header"> <h1>欢迎注册Tencent</h1> </div> <div data-role="main" class="ui-content"> <form method="get" action=""> <div class="ui-field-contain"> <label for="Rname">帐号:</label> <input type="text" name="u_name1" id="u_name1"> <br/> <label for="Rpassword">密码:</label> <input type="password" name="u_password1" id="u_password1"> <br/> <label for="Repassword">重复密码:</label> <input type="password" name="u_password2" id="u_password2"> <div style="margin-top: 20%;"> <input type="button" value="确定注册" onclick="register()" /> <a href="#pageLogin" data-role="button" data-transition="flip" data-direction="reverse">返回</a> </div> </div> </form> </div> <div data-role="footer" style="text-align: center" data-position="fixed"> <p>Copyright © 1998 - 2017 Tencent</p> </div> </div> </body> </html>
index.js
//测试登录 function login() { var u_user = document.getElementById("u_name").value; var u_password = document.getElementById("u_password").value; if((u_user == "admin") && (u_password == "admin888")) { alert("登录成功!不作处理!"); } else { alert("用户名或者密码错误,登录失败!"); location.href = "index.html#pageLogin"; } } //测试注册 function register() { var u_user1 = document.getElementById("u_name1").value; var u_password1 = document.getElementById("u_password1").value; var u_password2 = document.getElementById("u_password2").value; if((u_user1 == "root") && (u_password1 == "123456") && (u_password2 == u_password1)) { alert("注册成功!返回登录页面!"); location.href = "index.html#pageLogin"; } else { alert("注册失败,返回登录页面!"); location.href = "index.html#pageLogin"; } }
我们有两个方法来进行软件设计:一个是让其足够的简单以至于让BUG无法藏身;另一个就是让其足够的复杂,让人找不到BUG。前者更难一些。