素材牛VIP会员

JS仿支付宝多框隐藏输入

 所属分类:网页特效-输入/选择框/联动

 浏览:2151次  评论:0次  更新时间:2016-10-25
牛币素材VIP可免积分下载
JS仿支付宝多框隐藏输入兼容IE9
积分说明:注册即送10牛币,每日签到可获得5牛币,成为VIP会员可永久免牛币下载!   充值积分   充值会员   更多说明»
素材描述:仿支付宝监听键盘的敲击事件,一共六个input框,当第一个输入完毕,下一个框自动获取光标,继续输入。并可以自定义获取输入值。

详细介绍

特效介绍:

CSS样式

.input {
	width:330px;
	margin:auto;
	margin-bottom:20px;
}
input:last-child {
     border-right: 1px solid #999;
 }
input {
    border-top: 1px solid #909090;
    border-bottom: 1px solid #909090;
    border-left: 1px solid #909090;
    border-right: 1px solid #909090;
    width: 45px;
    height: 45px;
    outline:none;
    font-family: inherit;
    font-size: 28px;
    font-weight: inherit;
    text-align: center;
    line-height: 45px;
    color: #c2c2c2;
    background: rgba(255,255,255,0);
    border-radius: 5px;
}
.showNum{
    width: 300px;
    height: 40px;
    line-height: 40px;
    text-align: center;
    border: 1px solid #cccccc;
    cursor: pointer;
	margin:auto;
}

HTML结构

<div class="input">
<input type="password" class="inpVal1" placeholder="|" maxlength="1">
<input type="password" class="inpVal2" placeholder="|" maxlength="1">
<input type="password" class="inpVal3" placeholder="|" maxlength="1">
<input type="password" class="inpVal4" placeholder="|" maxlength="1">
<input type="password" class="inpVal5" placeholder="|" maxlength="1">
<input type="password" class="inpVal6" placeholder="|" maxlength="1">
</div>
<p class="showNum">单击显示密码..</p>

javaScript结构

/*模拟支付宝的密码输入形式*/
(function (window, document) {
var showNum=document.getElementsByClassName('showNum')[0];
showNum.onclick=function(){
    var inpVal1=document.querySelector('.inpVal1').value;
    var inpVal2=document.querySelector('.inpVal2').value;
    var inpVal3=document.querySelector('.inpVal3').value;
    var inpVal4=document.querySelector('.inpVal4').value;
    var inpVal5=document.querySelector('.inpVal5').value;
    var inpVal6=document.querySelector('.inpVal6').value;
    var val=inpVal1+""+inpVal2+""+inpVal3+""+inpVal4+""+inpVal5+""+inpVal6;
    showNum.innerHTML="您输入的是----"+val;
    console.log(val);
};
var active = 0,
        inputBtn = document.querySelectorAll('input');
for (var i = 0; i < inputBtn.length; i++) {
    inputBtn[i].addEventListener('click', function () {
        inputBtn[active].focus();
    }, false);
    inputBtn[i].addEventListener('focus', function () {
        this.addEventListener('keyup', listenKeyUp, false);
    }, false);
    inputBtn[i].addEventListener('blur', function () {
        this.removeEventListener('keyup', listenKeyUp, false);
    }, false);
}
/*监听键盘的敲击事件*/
function listenKeyUp() {
    if (!isNaN(this.value) && this.value.length != 0) {
        if (active < 5) {
            active += 1;
        }
        inputBtn[active].focus();
    } else if (this.value.length == 0) {
        if (active > 0) {
            active -= 1;
        }
        inputBtn[active].focus();
    }
}
})(window, document);

讨论这个素材(0)回答他人问题或分享使用心得会奖励牛币

〒_〒 居然一个评论都没有……

 文明上网,理性发言!   😉 阿里云幸运券,戳我领取
我的牛币余额:0
所需牛币:1 开始下载

牛币获取:签到、评论、充值    » 在线充值(10牛币=1元)