很多密码框都有个眼睛标记,点击能显示密码。原理就是点击切换password为text等显示
下面上代码
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title></title> 6 <style type="text/css"> 7 .pass{ 8 width:200px; 9 height: 20px; 10 } 11 </style> 12 <script> 13 window.onload=function(){ 14 var btn=document.getElementById("btn"); 15 var pass=document.getElementById("pass") 16 btn.onmousedown=function(){ 17 pass.type="number" 18 }; 19 btn.onmouseup=btn.onmouseout=function(){ 20 pass.type="password" 21 } 22 } 23 </script> 24 </head> 25 <body> 26 <input type="password" name="" id="pass" value="123456" class="pass"/> 27 <input type="button" name="" id="btn" value="点击显示" /> 28 </body> 29 </html>