javascript解鎖前端密碼框常見功能做法
前言
學(xué)前端最基本的登錄頁面肯定要會(huì)寫,那登錄頁面里面的密碼框的功能設(shè)計(jì)就需要好好打磨,主要功能有顯示密碼明文,密碼檢測信息提示等等,那么本篇博客將寫寫這些功能結(jié)合js怎么做,很簡單,看一下就會(huì)了。
顯示隱藏密碼明文
1.用到的圖片素材


2.代碼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.box{
position: relative;
width: 400px;
border-bottom: 1px solid #ccc;
margin: 100px auto;
}
.box input{
width: 370px;
height: 30px;
border: 0;
outline: none;
}
.box .image{
position: absolute;
top:2px;
right: 2px;
border: 1px solid #ccc;
background-color: #ccccccba;
border-radius: 50%;
overflow: hidden;
}
.box img{
vertical-align: bottom; /*父盒子是由img撐開的,所以要去除下面的間隙*/
width: 22px;
}
</style>
</head>
<body>
<div class="box">
<div class="image">
<img src="close.png" alt="" id="img">
</div>
<input type="password" id="pwd">
</div>
<script>
var img = document.getElementById('img');
var pwd = document.getElementById('pwd');
var flag = 0;
img.onclick = function(){
if(flag == 0){
pwd.type = 'text';
this.src='open.png'; // this指向事件函數(shù)的調(diào)用者,即img
flag = 1;
}else{
pwd.type = 'password';
this.src='close.png';
flag = 0;
}
}
</script>
</body>
</html>
3.結(jié)果演示

密碼框驗(yàn)證信息
1.用到的圖片素材



2.代碼
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.register{
width: 600px;
margin: 100px auto;
}
.ipt{
width: 250px;
border: 1px solid #999;
outline: none;
}
.message{
display: inline-block;
height: 20px;
font-size: 12px;
color: #999;
background: url(mess.png) no-repeat left center;
padding-left: 30px;
}
.wrong{
color: red;
background: url(wrong.png) no-repeat left center;
}
.right{
color: green;
background: url(right.png) no-repeat left center;
}
</style>
</head>
<body>
<div class="register">
<input type="password" class="ipt">
<p class="message">請(qǐng)輸入6~16位密碼</p>
</div>
<script>
var ipt = document.querySelector('.ipt');
var msg = document.querySelector('.message');
ipt.onfocus = function(){
this.style.borderColor = 'skyblue'
}
ipt.onblur = function(){
this.style.borderColor = '#999';
if(this.value.length<6 || this.value.length>16){
msg.className = 'message wrong';
msg.innerHTML = '你輸入的位數(shù)不符合要求6~16位!';
}else{
msg.className = 'message right';
msg.innerHTML = '你輸入的正確!';
}
}
</script>
</body>
</html>
3.結(jié)果演示

結(jié)語
以上就是javascript解鎖前端密碼框常見功能做法的詳細(xì)內(nèi)容,更多關(guān)于javascript前端密碼框功能做法的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
js實(shí)現(xiàn)每日自動(dòng)換一張圖片的方法
這篇文章主要介紹了js實(shí)現(xiàn)每日自動(dòng)換一張圖片的方法,涉及javascript操作圖片與日期的相關(guān)技巧,非常簡單實(shí)用,需要的朋友可以參考下2015-05-05
如何實(shí)現(xiàn)textarea里的不同文本顯示不同顏色
如何實(shí)現(xiàn)textarea里的不同文本顯示不同顏色呢?控制textarea的style設(shè)置Textarea以及把文本放到標(biāo)記里都不會(huì)起作用,下面有個(gè)不錯(cuò)的解決方法,感興趣的朋友可以了解下2014-01-01
doctype后如何獲得body.clientHeight的方法
doctype后如何獲得body.clientHeight的方法...2007-07-07
uniapp微信小程序?qū)崿F(xiàn)一個(gè)頁面多個(gè)倒計(jì)時(shí)
這篇文章主要為大家詳細(xì)介紹了uniapp微信小程序?qū)崿F(xiàn)一個(gè)頁面多個(gè)倒計(jì)時(shí),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-11-11

