六位独立密码框

找了好多独立密码框架,都有各种各样的bug,自己完善的密码框,希望能有人能用上!



html代码:

<div class="content">
       <form action="" method="get" id="pass_input">
           <div class="input_box">
               <span>支付密码:</span>
               <div class="box">
                   <input type="text" name=""  class="pass one" onselectstart="return false" autocomplete="off" οnfοcus="this.type='password'"/>
                   <input type="text" name="" class="pass two" autocomplete="off" οnfοcus="this.type='password'"/>
                   <input type="text" name=""  class="pass three" autocomplete="off" οnfοcus="this.type='password'"/>
                   <input type="text" name=""  class="pass four" autocomplete="off" οnfοcus="this.type='password'"/>
                   <input type="text" name=""  class="pass five" autocomplete="off" οnfοcus="this.type='password'"/>
                   <input type="text" name=""  class="pass six" autocomplete="off" οnfοcus="this.type='password'"/>
                   <i class="am-icon-eye-slash eyeBtn"></i>
                   <div style="clear: both"></div>
               </div>
               <p class="hide">请输入六位数字密码</p>
           </div>
           <div class="content_input">
               <button type="button" class="btn_dredge" οnclick="confirm()">确 定</button>
           </div>
       </form>

   </div>

js代码:

/*密码组件*/
   (function(){
    var txts = document.getElementsByClassName('pass');
    pass(txts);/*密码框*/
    var icon = $(".eyeBtn");
    var passEye = $(".pass");
    eye(icon,passEye);/*眼睛操作*/
    $(".one").focus(function(){
    $(this).css("border-color","#51bef5")
    })
   })();

function pass(txts){
    for (var i = 0; i < txts.length; i++) {
        var t = txts[i];
        var _this = this;
        t.index = i;
        t.setAttribute("readonly", true);
        t.onkeyup = function (e) {
            if (e.keyCode == 8) { /*删除*/
                if (this.value == "") {
                    var prop = this.index - 1;
                    if (prop < 0) return;
                    txts[prop].removeAttribute("readonly");
                    txts[prop].removeAttribute("disabled");
                    txts[prop].style = "border-color:#51bef5";
                    txts[prop].focus();
                    this.setAttribute("readonly", true);
                    this.setAttribute("disabled", true);
                    this.style = "border-color:#ddd";
                    this.value = "";
                }
            } else {
                if (this.value == "") {
               
                } else {
                    reg = /^[0-9]*$/; /*填写*/
                    if (!reg.test(this.value)) {
                        this.value = "";
                        return false;
                    }
                    this.value = this.value.substr(-1);
                    var next = this.index + 1;
                    if (next > txts.length - 1) return;
                    this.setAttribute("readonly", true);
                    this.setAttribute("disabled", true);
                    this.style = "border-color:#ddd";
                    txts[next].removeAttribute("readonly");
                    txts[next].removeAttribute("disabled");
                    txts[next].style = "border-color:#51bef5";
                    txts[next].focus();
                }
            }
        }
    }
    txts[0].removeAttribute("readonly");
}


//眼睛提示
function eye(icon,passEye){
icon.mousedown(function () {
icon.removeClass("am-icon-eye-slash").addClass("am-icon-eye");
   passEye.attr('type', 'number');
})
icon.mouseup(function () {
  icon.removeClass("am-icon-eye").addClass("am-icon-eye-slash");
   passEye.attr('type', 'password');
})
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值