JS實(shí)現(xiàn)密碼框效果
在輸入密碼時(shí),將密碼的長度設(shè)置為6-16,且在密碼長度出現(xiàn)小于6或是大于16時(shí),會(huì)出現(xiàn)提示,效果如下圖



1. 此事件為失去焦點(diǎn)事件,當(dāng)鼠標(biāo)離開密碼框且點(diǎn)擊旁邊就會(huì)觸發(fā)事件 2. 輸入密碼會(huì)出現(xiàn)提示,事件發(fā)生與密碼的長度有關(guān) 3. 根據(jù)長度再來判斷該提示的消息與效果.
代碼如下:
<!DOCTYPE html><html lang='en'><head> <meta charset='UTF-8'> <meta name='viewport' content='width=device-width, initial-scale=1.0'> <meta http-equiv='X-UA-Compatible' content='ie=edge'> <title>密碼框</title> <style type='text/css'> div{ width: 600px; margin: 100px auto; } .massage{ background-image: url(gth.png); background-repeat:no-repeat; background-position: left center; color:black; display: inline-block; padding-left: 20px; } .right{ background-image: url(right.png); background-repeat: no-repeat; color: green; } .wrong{ background-repeat: no-repeat; background-image: url(wrong.png); color: red; } </style></head><body> <div class='register'> <input type='password' id='pwd'> <p class='massage'>請(qǐng)輸入6-16位密碼</p> </div> <script> var pwd=document.querySelector(’#pwd’); var aa=document.querySelector(’.massage’); pwd.onblur= function(){ if(this.value.length>16 || this.value.length<6){ aa.innerText=’錯(cuò)誤,請(qǐng)輸入6-16為密碼’; aa.className=’massage wrong’; }else{ aa.className=’massage right’; aa.innerText=’密碼正確’; } } </script></body></html>
以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. ASP新手必備的基礎(chǔ)知識(shí)2. CentOS郵箱服務(wù)器搭建系列——SMTP服務(wù)器的構(gòu)建( Postfix )3. PHP基礎(chǔ)之生成器4——比較生成器和迭代器對(duì)象4. asp文件用什么軟件編輯5. Vue axios獲取token臨時(shí)令牌封裝案例6. 利用CSS制作3D動(dòng)畫7. golang中json小談之字符串轉(zhuǎn)浮點(diǎn)數(shù)的操作8. js實(shí)現(xiàn)計(jì)算器功能9. 通過IEAD+Maven快速搭建SSM項(xiàng)目的過程(Spring + Spring MVC + Mybatis)10. JS中6個(gè)對(duì)象數(shù)組去重的方法

網(wǎng)公網(wǎng)安備