完成登录与注册页面的前端

完成登录与注册页面的HTML+CSS+JS,其中的输入项检查包括:

用户名6-12位

首字母不能是数字

只能包含字母和数字

密码6-12位

注册页两次密码是否一致

 

 

登录html

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>MIS问答平台</title>
 6     <link rel="stylesheet" href="../static/css/dl.css">
 7 
 8     <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
 9     <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
10     <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
11     <script src="../static/javascript/dl.js"></script>
12 
13 
14 </head>
15 <body class="body">
16 
17 <div id="dljm" class="panel panel-info">
18     <h2 class="deng" class="panel-title">登陆</h2>
19     <div id="nr" class="panel-body">
20         <form>
21             <div class="input_box">
22                 Username:<input type="text" id="username" placeholder="请输入用户名">
23             </div>
24             <br>
25             <div class="input_box">
26                 Password: <input type="password" id="password" placeholder="请输入密码">
27             </div>
28             <div class="error_box" id="error_box"><br></div>
29             <div class="bt">
30 
31                 <button onclick="fnLogin()" >登录</button>
32             </div>
33             <br>
34             <input type="radio"  name="role" value="stu">学生
35             <input type="radio" name="role" value="tea">教师<br>
36             <input type="checkbox" value="true"><span>记住我</span><br><a
37                 href="http://www.gzcc.cn/html/yonghufenglei/xuesheng/">登陆遇到问题</a><br>
38 
39         </form>
40         <p class="footer"><i>版权@mis15</i></p>
41     </div>
42 
43 </div>
44 </body>
45 </html>

登录js

 1          function fnLogin() {
 2              var un = document.getElementById("username");
 3              var us = document.getElementById("password");
 4              var uE=document.getElementById("error_box")
 5 
 6              uE.innerHTML="<br>"
 7              if (un.value.length < 6 || un.value.length > 20) {
 8                  document.getElementById('error_box').innerHTML = "用户名必须在6-20个字符之间";
 9                  return;
10              }else if((un.value.charCodeAt(0)>=48)&&(un.value.charCodeAt(0)<=57)){
11                  uE.innerHTML="用户名首字母不能为数字";
12                  return;
13 
14              }
15              else for(var i=0;i<un.value.length;i++){
16                  if (((un.value.charCodeAt(i)<48)||(un.value.charCodeAt(i)>57))&&((un.value.charCodeAt(i)<97)||(un.value.charCodeAt(i)>122))){
17                      uE.innerHTML="用户名只能为数字或字母";
18                      return
19 
20                  }
21 
22                  }
23              if (us.value.length < 6 || us.value.length > 20) {
24                  document.getElementById('error_box').innerHTML = "密码必须在6-20个字符之间";
25                  return false;
26              }
27          }

登录和注册的css

 1 .deng {
 2     text-align: center;
 3     background-color: lightblue;
 4 }
 5 
 6 .dljm {
 7     width: 400px;
 8     align-content: center;
 9 }
10 
11 .footer {
12     background-color: lightblue;
13     text-align: center;
14 }
15 
16 div {
17     margin-left: auto;
18     margin-right: auto;
19     width: 300px;
20 
21 }
22 
23 .error_box {
24     color: red;
25 }
26 
27 button {
28 
29     font-size: 15px;
30     text-align: center;
31     background-color: lightblue;
32     height: 30px;
33     width: 130px;
34     font-family: "Adobe 宋体 Std L";
35     margin:0 auto;display:block;
36 }

注册html

 1 <!DOCTYPE html>
 2 <html lang="en">
 3 <head>
 4     <meta charset="UTF-8">
 5     <title>MIS问答平台</title>
 6     <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
 7     <script src="http://cdn.static.runoob.com/libs/jquery/2.1.1/jquery.min.js"></script>
 8     <script src="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/js/bootstrap.min.js"></script>
 9     <link rel="stylesheet" href="../static/css/dl.css">
10     <script src="../static/javascript/zhuce.js"></script>
11 </head>
12 <body>
13 <div id="zcjm" class="panel panel-info">
14     <h2 class="deng" class="panel-title">注册</h2>
15     <div id="nr2" class="panel-body">
16         <form>
17             <div class="input_box">
18                 Username :<input type="text" id="username" placeholder="请输入你的用户名">
19             </div>
20             <br>
21             <div class="input_box">
22                 Userphone:<input type="text" id="userphone" placeholder="请输入你的手机号">
23             </div>
24             <br>
25             <div class="input_box">
26                 Password : <input type="password" id="password" placeholder="请输入密码">
27             </div>
28             <br>
29             <div class="input_box">
30                 Password : <input type="password" id="password2" placeholder="请再次输入密码">
31             </div>
32 
33             <div class="error_box" id="error_box"><br></div>
34             <div class="bt">
35 
36                 <button onclick="fnzhuce()">注册</button>
37             </div>
38         </form>
39 
40 
41     </div>
42 
43 
44 </div>
45 </body>
46 </html>

注册js

 1 function fnzhuce() {
 2     var un = document.getElementById("username");
 3     var us = document.getElementById("password");
 4     var uE = document.getElementById("error_box");
 5     var uP = document.getElementById("userphone");
 6     var us2 = document.getElementById("password2");
 7 
 8     uE.innerHTML = "<br>";
 9     if (un.value.length < 6 || un.value.length > 20) {
10         document.getElementById('error_box').innerHTML = "用户名必须在6-20个字符之间";
11         return;
12     } else if ((un.value.charCodeAt(0) >= 48) && (un.value.charCodeAt(0) <= 57)) {
13         uE.innerHTML = "用户名首字母不能为数字";
14         return;
15 
16     }
17     else for (var i = 0; i < un.value.length; i++) {
18             if (((un.value.charCodeAt(i) < 48) || (un.value.charCodeAt(i) > 57)) && ((un.value.charCodeAt(i) < 97) || (un.value.charCodeAt(i) > 122))) {
19                 uE.innerHTML = "用户名只能为数字或字母";
20                 return;
21 
22             }
23 
24         }
25     for (var i = 0; i <12; i++) {
26         if (((uP.value.charCodeAt(i) < 48) || (uP.value.charCodeAt(i) > 57)) || uP.value.length != 11) {
27             uE.innerHTML = "请输入正确手机号";
28             return
29         }
30     }
31 
32     if (us.value.length < 6 || us.value.length > 20) {
33         document.getElementById('error_box').innerHTML = "密码必须在6-20个字符之间";
34         return ;
35     }
36     if (us2.value!=us.value){
37         uE.innerHTML = "两次输入的密码必须一致";
38 
39 
40     }
41 
42 }

 

posted @ 2017-10-31 12:56  044潘育珊  阅读(140)  评论(0编辑  收藏  举报