js模拟支付密码输入

效果图:

HTML代码:


   
   

请输入您的专享密码

确认
Css代码:

 body{
            background: #fff;
            font-size:0.7rem;
        }
        input{
            color:transparent;
            text-shadow:0 0 0 #000;
            font-size:1rem;
        }
        .rec_in_container{
            padding:0 1.25rem;
        }
        .rec_in_container p{
            margin:1.5rem 0;
            color: #999;
        }
        .rec_in_show{
            position: relative;
        }
        .rec_in_input{
            height: 2.35rem;
            width: 200%;
            position: absolute;
            top:0;
            left:0;
            z-index: 1;
            filter:alpha(opacity=0);
            -moz-opacity:0;
            opacity:0;
            margin-left: -100%;
            color:transparent;
            text-shadow:0 0 0 #000;
        }
        .rec_in_pw{
            display: -webkit-box; /* OLD - iOS 6-, Safari 3.1-6 */ display: -moz-box; /* OLD - Firefox 19- (buggy but mostly works) */ display: -ms-flexbox; /* TWEENER - IE 10 */ display: -webkit-flex; /* NEW - Chrome */ display: flex; /* NEW, Spec - Opera 12.1, Firefox 20+ */
            -webkit-box-pack: space-between;
            -moz-justify-content: space-between;
            -webkit-justify-content: space-between;
            justify-content: space-between;
        }
        .rec_in_pw div{
            width: 2.35rem;
            height:2.35rem;
            background: #f0f0f0;
            padding: 0;
            text-align: center;
            position: relative;
        }
        .rec_in_pw div i{
            display: inline-block;
            width: .4rem;
            height:.4rem;
            position: absolute;
            top:0;
            right:0;
            left: 0;
            bottom: 0;
            margin: auto;
            background: #000;
            border-radius: 50%;
            display: none;
        }
        .rec_in_submit{
            text-align: center;
            margin-top:2rem;
        }
        .rec_in_submit span{
            display: inline-block;
            width: 14.05rem;
            height:2.2rem;
            background: #ff9a96;
            color: #fff;
            font-size:.9rem;
            line-height: 2.4rem;
            border-radius: .2rem;
        }
Js代码:

(function(){
            var container = document.getElementById("inputBoxContainer");
            boxInput = {
                maxLength:6,
                realInput:"",
                bogusInput:"",
                bogusInputArr:"",
                callback:"",
                init:function(fun){
                    var that = this;
                    this.callback = fun;
                    that.realInput = container.children[0];
                    that.bogusInput = container.children[1];
                    that.bogusInputArr = that.bogusInput.children;
                    that.realInput.oninput = function(){
                        that.setValue();
                    }
                    that.realInput.onpropertychange = function(){
                        that.setValue();
                    }
                },
                setValue:function(){
                    this.realInput.value = this.realInput.value.replace(/\D/g,"");
                    var real_str = this.realInput.value;
                    var real_len = this.realInput.value.length > this.maxLength ? this.maxLength : this.realInput.value.length;
                    for(var i=0 ;i
   
   
    
    = this.maxLength){
                        this.realInput.value = real_str.substring(0,this.maxLength);
                        this.callback();
                    }
                },
                getBoxInputValue:function(){
                    return this.realInput.value;
                }
            }
        })()
        boxInput.init(function(){
            //每次输入回调
        });
        document.getElementById("confirmButton").onclick = function(){
            checkId();
        }
        function checkId(){
            //判断是否符合资格
            if(boxInput.getBoxInputValue().length == 6){
                console.log(boxInput.getBoxInputValue());
            }
        }
   
   


  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值