js 判斷登錄界面的賬號(hào)密碼是否為空
判斷登錄界面的賬號(hào)密碼是否為空的時(shí)候又不想用alert顯示就需要用display來隱藏alert啦(在設(shè)置時(shí)切忌要將隱藏的內(nèi)容寫在賬號(hào)和密碼的div中,否則會(huì)根據(jù)屏幕的分辨率不同而有所變化,這是本人教訓(xùn))
首先要定義賬號(hào)、密碼和隱藏部分的id,即var x=document.getElementById("id"),包括按鈕的id,然后點(diǎn)擊登錄按鈕的時(shí)候(btn.onclick=function(){具體的選擇隱藏和顯示的內(nèi)容})要寫函數(shù)進(jìn)行選擇隱藏和顯示;在重置按鈕的是(btn.onclick=function(){清空的內(nèi)容,包括登錄按鈕顯示的內(nèi)容})
具體代碼如下:
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="UTF-8" />
<title>請(qǐng)登錄</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">
賬號(hào):<input type="text" id="username"/><span id="u" style="display: none;color: red;font-size:13px;">*請(qǐng)輸入賬號(hào)!</span>
</div>
<div class="password">
密碼:<input type="password" id="password"/><span id="p" style="display: none;color: red;font-size:13px;">*請(qǐng)輸入密碼!</span>
</div>
<div class="empty">
<span id="up" style="display: none;color: red;font-size:13px;">*賬號(hào)或密碼錯(cuò)誤</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");
//點(diǎn)擊登錄按鈕時(shí)判斷賬號(hào)、密碼是否為空或錯(cuò)誤
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";
}
}
//點(diǎn)擊重置按鈕時(shí)清空賬號(hào)密碼
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('賬號(hào)或密碼錯(cuò)誤!');
}
//判斷賬號(hào)密碼是否為空則彈出
if (""==x) {
alert("請(qǐng)輸入賬號(hào)!");
flag=false;
return false;
}
else if(""==y){
alert("請(qǐng)輸入密碼!");
flag=false;
return false;
}
if(flag==true){
flag=true;
}*/
</script>
</body>
</html>
以上就是本文的全部?jī)?nèi)容,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作能帶來一定的幫助,同時(shí)也希望多多支持腳本之家!
- JavaScript登錄記住密碼操作(超簡(jiǎn)單代碼)
- JS實(shí)現(xiàn)登錄頁(yè)面記住密碼和enter鍵登錄方法推薦
- 通過jquery.cookie.js實(shí)現(xiàn)記住用戶名、密碼登錄功能
- JS實(shí)現(xiàn)登錄頁(yè)密碼的顯示和隱藏功能
- Javascript實(shí)現(xiàn)登錄記住用戶名和密碼功能
- jquery.cookie.js實(shí)現(xiàn)用戶登錄保存密碼功能的方法
- javascript記住用戶名和登錄密碼(兩種方式)
- JSP實(shí)現(xiàn)用戶登錄、注冊(cè)和退出功能
- 用JS實(shí)現(xiàn)簡(jiǎn)單的登錄驗(yàn)證功能
- js實(shí)現(xiàn)登錄時(shí)記住密碼的方法分析
相關(guān)文章
JavaScript代碼實(shí)現(xiàn)春晚劉謙魔術(shù)的模擬程序
昨晚春晚上劉謙的兩個(gè)魔術(shù)表演都非常精彩,尤其是第二個(gè)魔術(shù),他演繹了經(jīng)典的約瑟夫環(huán)問題!約瑟夫環(huán)是一個(gè)經(jīng)典的數(shù)學(xué)問題,本文給出了完整的 JavaScript 代碼實(shí)現(xiàn),感興趣的同學(xué)可以自己動(dòng)手實(shí)現(xiàn)一下2024-02-02
基于javascript html5實(shí)現(xiàn)3D翻書特效
這篇文章主要介紹了基于javascript html5實(shí)現(xiàn)翻書特效的實(shí)現(xiàn)方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-03-03
JavaScript中數(shù)據(jù)類型轉(zhuǎn)換總結(jié)
在js中,數(shù)據(jù)類型轉(zhuǎn)換分為顯式數(shù)據(jù)類型轉(zhuǎn)換和隱式數(shù)據(jù)類型轉(zhuǎn)換。本文將對(duì)此進(jìn)行介紹,具有一定的參考價(jià)值,需要的朋友一起來看下吧2016-12-12
解決JSON.stringify()自動(dòng)將中文轉(zhuǎn)譯成unicode的問題
下面小編就為大家分享一篇解決JSON.stringify()自動(dòng)將中文轉(zhuǎn)譯成unicode的問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-01-01

