移动端支付6位密码框
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> <script src="http://zeptojs.com/zepto.min.js"></script> <title>手机端六位密码输入</title> <style> *{margin: 0;padding: 0;} html,body{width: 100%;height: 100%} .main{width: 100%;height: 100%;background: rgba(0, 0, 0 ,0.5);position: absolute;top:0} .pwd-box{ width:324px; height: 70px; position: relative; border: 1px solid #9f9fa0; border-radius: 3px; overflow:hidden; margin:0 auto; top:30%; } .pwd-box input[type="tel"]{ width: 324px; height: 70px; color: transparent; position: absolute; top: 0; left: 0; border: none; font-size: 18px; opacity: 0; z-index: 1; letter-spacing: 35px; } .fake-box input{ width: 50px; height: 50px; border: none; text-align: center; font-size: 30px; } .fake-box input:nth-last-child(1){ border:none; } p{text-align: center;font-size: 20px;color: white} </style> </head> <body> <div class="main"> <div class="pwd-box"> <p>输入邀请码</p> <input type="tel" maxlength="6" class="pwd-input" id="pwd-input"> <div class="fake-box"> <input type="text" readonly=""> <input type="text" readonly=""> <input type="text" readonly=""> <input type="text" readonly=""> <input type="text" readonly=""> <input type="text" readonly=""> </div> </div> </div> <script> var $input = $(".fake-box input"); var boxInput=$("#pwd-input"); boxInput.focus(); boxInput.on("input", function() { var pwd = $(this).val().trim(); for (var i = 0, len = pwd.length; i < len; i++) { $input.eq("" + i + "").val(pwd[i]); } $input.each(function() { var index = $(this).index(); if (index >= len) { $(this).val(""); } }); if (len == 6) { //执行其他操作 } }); </script> </body> </html>