判斷登錄界面的賬號密碼是否為空的時候又不想用alert顯示就需要用display來隱藏alert啦(在設置時切忌要將隱藏的內容寫在賬號和密碼的div中,否則會根據屏幕的分辨率不同而有所變化,這是本人教訓)
創新互聯是一家業務范圍包括IDC托管業務,網絡空間、主機租用、主機托管,四川、重慶、廣東電信服務器租用,西部信息服務器租用,成都網通服務器托管,成都服務器租用,業務范圍遍及中國大陸、港澳臺以及歐美等多個國家及地區的互聯網數據服務公司。
首先要定義賬號、密碼和隱藏部分的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"> <div class="dlsy"> <br/><br/><br/> <div class="username"> 賬號:<input type="text" id="username"/><span id="u" >*請輸入賬號!</span> </div> <div class="password"> 密碼:<input type="password" id="password"/><span id="p" >*請輸入密碼!</span> </div> <div class="empty"> <span id="up" >*賬號或密碼錯誤</span> </div> <div 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> </div> </div> </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>
以上就是本文的全部內容,希望本文的內容對大家的學習或者工作能帶來一定的幫助,同時也希望多多支持創新互聯!
網站名稱:js判斷登錄界面的賬號密碼是否為空
當前地址:http://www.yijiale78.com/article30/jceeso.html
成都網站建設公司_創新互聯,為您提供外貿建站、動態網站、微信小程序、小程序開發、建站公司、網站營銷
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯