码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2017-11-01 21:37:34      阅读:194      评论:0      收藏:0      [点我收藏+]

标签:bottom   head   完成   用户   groov   onclick   字母   hold   center   

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

用户名6-12位

首字母不能是数字

只能包含字母和数字

密码6-12位

注册页两次密码是否一致

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link href="../static/vv.css" rel="stylesheet" type="text/css">
    <script src="../static/vv.js"></script>

</head>
<body bgcolor="#778899" class="div4">

<div class="div1">
    <h2 class="title">
            <div class="normal-title">
                <a class="div2" href="vv.html">登录</a>
                <b>|</b>
                <a  class="div2" href="vv1.html">注册</a>
            </div>
        </h2>

    <div class="div3">
        用户:<input id="username" type="text" placeholder="请输入昵称">
    </div>
    <div class="div3">
        密码:<input id="userpass" type="text" placeholder="请输入密码">
    </div>
    <div id="error_box"><br></div>
     <div class="div3">
        <button onclick="myLogin()">Login</button>
    </div>
    <div class="div2">ByYin</div>
</div>
<br>
</body>
</html>

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>注册</title>
    <link href="../static/vv.css" rel="stylesheet" type="text/css">
    <script src="../static/new.js"></script>

</head>
<body bgcolor="#778899" class="div4">
<div class="div1">
    <h2 class="title">
            <div class="normal-title">
                <a class="div2" href="vv.html">登录</a>
                <b>|</b>
                <a  class="div2" href="vv1.html">注册</a>
            </div>
        </h2>
    <div class="div3">
        用户:<input id="newname1" type="text" placeholder="请输入昵称">
    </div>
    <div class="div3">
        密码:<input id="newpass1" type="text" placeholder="请输入密码">
    </div>
    <div class="div3">
        密码:<input id="newpass2" type="text" placeholder="请再次输入密码">
    </div>
    <div id="error_box"><br></div>
     <div class="div3">
        <button onclick="myRegister()">Register</button>
    </div>
    <div class="div2">ByYin</div>
</div>
<br>
</body>
</html>

 

div{
margin: 0 auto;
text-align: center;
background-color: lightgray;
}
.div1{
width: 350px;
height: 250px;
border-color: lightgray;
border-style: groove;
border-width: 2px;
margin-top:100px ;
}
.div2{
font-family: 方正清刻本悦宋简体;
border-bottom-style: groove;
border-bottom-width: 2px;
line-height: 30px;
background-color: gainsboro;
}
.div3{
font-family: 幼圆;
width: 350px;
height: 50px;
font-size: 18px;
align:"center";
}
.div4{
background: url(http://p2.so.qhimgs1.com/bdr/_240_/t017dcea294f50fbf92.jpg);
}
 function myLogin() {
     var uName = document.getElementById("username");
     var uError = document.getElementById("error_box");
     var uPass =document.getElementById("userpass");
     uError.innerHTML="<br>"
     if (uName.value.length < 6||uName.value.length > 20) {
         uError.innerHTML = "用户名为6位到20位!"
         return;
     }
     else if ((uName.value.charCodeAt(0)) >= 48 && uName.value.charCodeAt(0) <= 57) {
         uError.innerHTML = "用户名首字母不能为数字"
         return;
     }
     else for(var i=0;i<uName.value.length;i++){
         if((uName.value.charCodeAt(i)<48||uName.value.charCodeAt(i)>57)&&(uName.value.charCodeAt(i)<97||uName.value.charCodeAt(i)>122)){
             uError.innerHTML="用户名只能为字母或数字"
             return;
         }
     }
     if (uPass.value.length<6||uPass.value.length>20){
         uError.innerHTML="密码为6-20位!"
         return;
     }
     window.alert("您已登录成功!")
 }


function myRegister() {
var nName = document.getElementById("newname1");
var nError = document.getElementById("error_box");
var nPass =document.getElementById("newpass1");
var nPass1=document.getElementById("newpass2")
nError.innerHTML="<br>"
if (nName.value.length < 6||nName.value.length > 20) {
nError.innerHTML = "用户名为6位到20位!"
return;
}
else if ((nName.value.charCodeAt(0)) >= 48 && nName.value.charCodeAt(0) <= 57) {
nError.innerHTML = "用户名首字母不能为数字"
return;
}
else for(var i=0;i<nName.value.length;i++){
if((nName.value.charCodeAt(i)<48||nName.value.charCodeAt(i)>57)&&(nName.value.charCodeAt(i)<97||nName.value.charCodeAt(i)>122)){
nError.innerHTML="用户名只能为字母或数字!"
return;
}
}
if (nPass.value.length<6||nPass.value.length>20){
nError.innerHTML="密码为6-20位!"
return;
}
if(nPass.value!=nPass1.value){
nError.innerHTML="您输入的密码不一致!请重新输入!"
return;
}
window.alert("您已注册成功!")
}
 技术分享技术分享技术分享技术分享技术分享技术分享

 

 

 

 

 

 

 

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

标签:bottom   head   完成   用户   groov   onclick   字母   hold   center   

原文地址:http://www.cnblogs.com/yin-yeah/p/7760768.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!