手机端六位密码输入框

来源:互联网 发布:阿里云1m宽带网速多少 编辑:程序博客网 时间:2024/04/26 07:19
  1. 转载自网名为qiuqingpo的网友
  2. <!DOCTYPE html>  
  3. <html>  
  4. <head>  
  5. <script src="http://zeptojs.com/zepto.min.js"></script>  
  6.   <title>手机端六位密码输入</title>  
  7. <style>  
  8. .pwd-box{  
  9.         width:310px;  
  10.         padding-left: 1px;  
  11.         position: relative;  
  12.         border: 1px solid #9f9fa0;  
  13.         border-radius: 3px;  
  14. over-flow:hidden  
  15.     }  
  16.     .pwd-box input[type="tel"]{  
  17.         width: 99%;  
  18.         height: 45px;  
  19.         color: transparent;  
  20.         position: absolute;  
  21.         top: 0;  
  22.         left: 0;  
  23.         border: none;  
  24.         font-size: 18px;  
  25.         opacity: 0;  
  26.         z-index: 1;  
  27.         letter-spacing: 35px;  
  28.     }  
  29.     .fake-box input{  
  30.         width: 44px;  
  31.         height: 48px;  
  32.         border: none;  
  33.         border-right: 1px solid #e5e5e5;  
  34.         text-align: center;  
  35.         font-size: 30px;  
  36.     }  
  37.     .fake-box input:nth-last-child(1){  
  38.         border:none;  
  39.     }  
  40. </style>  
  41. </head>  
  42. <body>  
  43. <div class="pwd-box">  
  44.     <input type="tel" maxlength="6" class="pwd-input" id="pwd-input">  
  45.     <div class="fake-box">  
  46.         <input type="password" readonly="">  
  47.         <input type="password" readonly="">  
  48.         <input type="password" readonly="">  
  49.         <input type="password" readonly="">  
  50.         <input type="password" readonly="">  
  51.         <input type="password" readonly="">  
  52.     </div>  
  53. </div>  
  54. <script>  
  55. var $input = $(".fake-box input");  
  56.             $("#pwd-input").on("input", function() {  
  57.                 var pwd = $(this).val().trim();  
  58.                 for (var i = 0len = pwd.length; i < len; i++) {  
  59.                     $input.eq("" + i + "").val(pwd[i]);  
  60.                 }  
  61.                 $input.each(function() {  
  62.                     var index = $(this).index();  
  63.                     if (index >= len) {  
  64.                         $(this).val("");  
  65.                     }  
  66.                 });  
  67.                 if (len == 6) {  
  68.                     //执行其他操作  
  69.                 }  
  70.             });  
  71. </script>  
  72. </body>  
  73. </html>  
原创粉丝点击