JavaScript 基础,登录验证

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>jsDemo</title>
</head>
<body>
    <p id="demo">ppp</p>

    <script>
        document.write(Date()).innerHTML=123;
        document.getElementById("demo").innerHTML=Date();
    </script>
    <button type="button" onclick=window.alert("number")>press</button>

</body>
</html>

 

 

 

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

    <script>
        function fnLogin(){
           var oUname = document.getElementById("uname")
           var oError=document.getElementById("error_box")
           var oUpass = document.getElementById("upass")
           if(oUname.value.length==0){
               oError.innerHTML="请输入用户名"
           }
           if(oUname.value.length<6){
               oError.innerHTML="用户名至少6位"
           }
           if(oUname.value.length>12){
               oError.innerHTML="用户名至多12位"
           }
           if(oUpass.value.length==0){
               oError.innerHTML="请输入密码"
           }
           if(oUpass.value.length<6){
               oError.innerHTML="密码至少6位"
           }
           if(oUpass.value.length>20){
               oError.innerHTML="密码至多20位"
           }

        }
    </script>

</head>
<body style="background-color:yellow">
<div class="box">
    <h2 class="denglu">登录</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>

 

.box{
    border:1px solid#cccccc;
    width:334px;
    margin:5px;
    text-align:center;
}
.denglu{
     background-color:pink;
     font-family:华文;
     font-size:40px;
}
.input_box{
    height:45px;
}

 

 

 

posted @ 2017-10-26 13:18  002邓诺斯  阅读(195)  评论(0编辑  收藏  举报