<pre id="bbfd9"><del id="bbfd9"><dfn id="bbfd9"></dfn></del></pre>

          <ruby id="bbfd9"></ruby><p id="bbfd9"><mark id="bbfd9"></mark></p>

          <p id="bbfd9"></p>

          <p id="bbfd9"><cite id="bbfd9"></cite></p>

            <th id="bbfd9"><form id="bbfd9"><dl id="bbfd9"></dl></form></th>

            <p id="bbfd9"><cite id="bbfd9"></cite></p><p id="bbfd9"></p>
            <p id="bbfd9"><cite id="bbfd9"><progress id="bbfd9"></progress></cite></p>
            java語言

            JavaScript判斷登錄界面的賬號密碼是否為空代碼

            時間:2025-02-20 19:18:38 java語言 我要投稿
            • 相關推薦

            JavaScript判斷登錄界面的賬號密碼是否為空代碼

              導語:利用display的none與block判斷登錄界面的賬號密碼是否為空的方法首先要定義賬號、密碼和隱藏部分的id,即var x=document.getElementById("id"),包括按鈕的id,然后點擊登錄按鈕的時候(btn.onclick=function(){具體的選擇隱藏和顯示的內容})要寫函數進行選擇隱藏和顯示;在重置按鈕的是(btn.onclick=function(){清空的內容,包括登錄按鈕顯示的內容}),下面是具體實現代碼。

              <html xmlns="http://www.w3.org/1999/xhtml" lang="en">

              <head>

              <meta charset="UTF-8" />

              <title>請登錄</title><base target="_blank" />

              <style>

              body{

              margin:0px auto;

              background-image: url(images/dlbj1.png) ;

              position: relative;

              }

              .dl{

              width: 380px ;

              height: 220px ;

              background-image: url(images/dl.png) ;

              text-align: center ;

              margin: auto ;

              margin-top: 15% ;

              position: center;

              }

              .btn{

              font-family : 微軟雅黑 ;

              font-size: medium ;

              }

              #username{

              max-width: 200px ;

              margin: 10px 0px 0px 0px ;

              height: 28px ;

              }

              #us{

              color: #FFFFFF ;

              font-family : 微軟雅黑;

              }

              #ps{

              color: #FFFFFF ;

              font-family : 微軟雅黑;

              }

              #password{

              max-width: 200px ;

              margin: 20px 0px 10px 0px ;

              height: 28px ;

              }

              </style>

              </head>

              <body>

              <form class="dl" method="post">

              <p class="dlsy">

              <br/><br/><br/>

              <p class="username">

              賬號:<input type="text" id="username"/><span id="u" style="display: none;color: red;font-size:13px;">*請輸入賬號!</span>

              </p>

              <p class="password">

              密碼:<input type="password" id="password"/><span id="p" style="display: none;color: red;font-size:13px;">*請輸入密碼!</span>

              </p>

              <p class="empty">

              <span id="up" style="display: none;color: red;font-size:13px;">*賬號或密碼錯誤</span>

              </p>

              <p class="btn">

              <button type="button" id="reset" class="btn btn-default button-rounded button-small">重置</button>

              <button type="button" id="submit" class="btn btn-default button-rounded button-small">登錄</button>

              </p>

              </p>

              </form>

              <script type="text/javascript">

              var x=document.getElementById("username");

              var y=document.getElementById("password");

              var btnSubmit = document.getElementById("submit");

              var btnReset = document.getElementById("reset");

              var u=document.getElementById("u");

              var p=document.getElementById("p");

              var up=document.getElementById("up");

              //點擊登錄按鈕時判斷賬號、密碼是否為空或錯誤

              btnSubmit.onclick=function(form){

              if(x.value==""){

              if(y.value==""){

              up.style.display="block";

              }

              else{

              u.style.display="block";

              up.style.display="none";

              }

              }

              else if(y.value==""){

              if(x.value==""){

              up.style.display="block";

              }

              else{

              p.style.display="block";

              up.style.display="none";

              }

              }

              else{

              u.style.display="none";

              up.style.display="block";

              p.style.display="none";

              }

              }

              //點擊重置按鈕時清空賬號密碼

              btnReset.onclick=function(form){

              x.value=""; //清空input里的value

              y.value="";

              u.style.display="none";

              up.style.display="none";

              p.style.display="none";

              }

              /*btn.onclick=function(form){

              /*if (x!="admin"||y!=123456){

              alert('賬號或密碼錯誤!');

              }

              //判斷賬號密碼是否為空則彈出

              if (""==x) {

              alert("請輸入賬號!");

              flag=false;

              return false;

              }

              else if(""==y){

              alert("請輸入密碼!");

              flag=false;

              return false;

              }

              if(flag==true){

              flag=true;

              }*/

              </script>

              </body>

              </html>

            【JavaScript判斷登錄界面的賬號密碼是否為空代碼】相關文章:

            判斷PHP數組是否為空的代碼08-26

            PHP如何判斷數組是否為空07-26

            PHP判斷數組是否為空的5大方法10-16

            判斷數組是否為空的五大方法10-24

            PHP五種方法實現數組是否為空的判斷08-12

            php動態生成JavaScript代碼10-03

            PHP中判斷變量為空的方法06-18

            javascript實現小球的自由移動代碼08-26

            JavaScript代碼的5個書寫壞習慣08-16

                    <pre id="bbfd9"><del id="bbfd9"><dfn id="bbfd9"></dfn></del></pre>

                    <ruby id="bbfd9"></ruby><p id="bbfd9"><mark id="bbfd9"></mark></p>

                    <p id="bbfd9"></p>

                    <p id="bbfd9"><cite id="bbfd9"></cite></p>

                      <th id="bbfd9"><form id="bbfd9"><dl id="bbfd9"></dl></form></th>

                      <p id="bbfd9"><cite id="bbfd9"></cite></p><p id="bbfd9"></p>
                      <p id="bbfd9"><cite id="bbfd9"><progress id="bbfd9"></progress></cite></p>
                      飘沙影院