基于JS实现类似支付宝支付密码输入框


Posted in Javascript onSeptember 02, 2016

本文实现的是一个类似支付宝支付密码的界面,只可以输入数字,且只可以输入6位

首先给大家展示下效果图,如果感觉不错,请参考实现代码。

基于JS实现类似支付宝支付密码输入框

1、样式表

.wrap{
margin: 10px auto;
width: 329px;
height: 640px; 
padding-top: 200px;
}
.inputBoxContainer{
width: 240px;
height: 50px;
margin: 0 auto;
position: relative;
}
.inputBoxContainer .bogusInput{
width: 100%;
height: 100%;
border: #c3c3c3 1px solid;
border-radius: 7px;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
overflow: hidden;
position: absolute;
z-index: 0;
}
.inputBoxContainer .realInput{
width: 100%;
height: 100%;
position: absolute;
top:0;
left: 0;
z-index: 1;
filter:alpha(opacity=0);
-moz-opacity:0;
opacity:0;
}
.inputBoxContainer .bogusInput input{
padding: 0;
width: 16.3%;
height: 100%;
float:left;
background: #ffffff;
text-align: center;
font-size: 20px;
border: none;
border-right: #C3C3C3 1px solid;
}
.inputBoxContainer .bogusInput input:last-child{
border: none;
}
.confirmButton{
width: 240px;
height: 45px;
border-radius: 7px;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
background: #f4f4f4;
border: #d5d5d5 1px solid;
display: block;
font-size: 16px;
margin: 30px auto;
margin-bottom: 20px;
}
.showValue{
width: 240px;
height: 22px;
line-height: 22px;
font-size: 16px;
text-align: center;
margin: 0 auto;
}

2、HTML代码

<div class="wrap">
<div class="inputBoxContainer" id="inputBoxContainer">
<input type="text" class="realInput"/>
<div class="bogusInput">
<input type="password" maxlength="6" disabled/>
<input type="password" maxlength="6" disabled/>
<input type="password" maxlength="6" disabled/>
<input type="password" maxlength="6" disabled/>
<input type="password" maxlength="6" disabled/>
<input type="password" maxlength="6" disabled/>
</div>
</div>
<button id="confirmButton" class="confirmButton">查看</button>
<p class="showValue" id="showValue"></p>
</div>

3、js代码控制逻辑效果

(function(){
var container = document.getElementById("inputBoxContainer");
boxInput = {
maxLength:"",
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.maxLength = that.bogusInputArr[0].getAttribute("maxlength");
that.realInput.oninput = function(){
that.setValue();
}
that.realInput.onpropertychange = function(){
that.setValue();
}
},
setValue:function(){
this.realInput.value = this.realInput.value.replace(/\D/g,"");
console.log(this.realInput.value.replace(/\D/g,""))
var real_str = this.realInput.value;
for(var i = 0 ; i < this.maxLength ; i++){
this.bogusInputArr[i].value = real_str[i]?real_str[i]:"";
}
if(real_str.length >= this.maxLength){
this.realInput.value = real_str.substring(0,6);
this.callback();
}
},
getBoxInputValue:function(){
var realValue = "";
for(var i in this.bogusInputArr){
if(!this.bogusInputArr[i].value){
break;
}
realValue += this.bogusInputArr[i].value;
}
return realValue;
}
}
})()
boxInput.init(function(){
getValue();
});
document.getElementById("confirmButton").onclick = function(){
getValue();
}
function getValue(){
document.getElementById("showValue").innerText = boxInput.getBoxInputValue();
}

以上所述是小编给大家介绍的基于JS实现类似支付宝支付密码输入框,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对三水点靠木网站的支持!

Javascript 相关文章推荐
快速解决FusionCharts联动的中文乱码问题
Dec 04 Javascript
JS判断、校验MAC地址的2个实例
May 05 Javascript
jQery使网页在显示器上居中显示适用于任何分辨率
Jun 09 Javascript
node.js中的fs.lstat方法使用说明
Dec 16 Javascript
javascript强制点击广告的方法
Feb 06 Javascript
JS实现拖动滚动条评分的效果代码分享
Sep 29 Javascript
vue.js+Element实现表格里的增删改查
Jan 18 Javascript
在axios中使用params传参的时候传入数组的方法
Sep 25 Javascript
详解ES6中的 Set Map 数据结构学习总结
Nov 06 Javascript
微信公众号平台接口开发 获取access_token过程解析
Aug 14 Javascript
viewer.js实现图片预览功能
Jun 24 Javascript
在vue中使用console.log无效的解决
Aug 09 Javascript
JavaScript中Number对象的toFixed() 方法详解
Sep 02 #Javascript
Node.js实现兼容IE789的文件上传进度条
Sep 02 #Javascript
AngularJs  Understanding Angular Templates
Sep 02 #Javascript
jquery 中toggle的2种用法详解(推荐)
Sep 02 #Javascript
浅谈JS中的三种字符串连接方式及其性能比较
Sep 02 #Javascript
AngularJs  E2E Testing 详解
Sep 02 #Javascript
解决node.js安装包失败的几种方法
Sep 02 #Javascript
You might like
windows服务器中检测PHP SSL是否开启以及开启SSL的方法
2014/04/25 PHP
PHP高手需要要掌握的知识点
2014/08/21 PHP
php实现过滤表单提交中html标签的方法
2014/10/17 PHP
PHP读取配置文件类实例(可读取ini,yaml,xml等)
2015/07/28 PHP
使用symfony命令创建项目的方法
2016/03/17 PHP
php 删除指定文件夹的实例讲解
2017/07/25 PHP
解决jQuery插件tipswindown与hintbox冲突
2010/11/05 Javascript
jquery uaMatch源代码
2011/02/14 Javascript
js操作label给label赋值及取label的值示例
2013/11/07 Javascript
js完美解决IE6不支持position:fixed的bug
2015/04/24 Javascript
js正则表达式中exec用法实例
2015/07/23 Javascript
探讨JavaScript标签位置的存放与功能有无关系
2016/01/15 Javascript
js操作DOM--添加、删除节点的简单实例
2016/07/08 Javascript
D3.js实现柱状图的方法详解
2016/09/21 Javascript
想学习javascript JS和jQuery哪个重要 先学哪个
2016/12/11 Javascript
javascript 中iframe高度自适应(同域)实例详解
2017/05/16 Javascript
浅析vue.js数组的变异方法
2018/06/30 Javascript
详解滑动穿透(锁body)终极探索
2019/04/16 Javascript
微信小程序wx.request的简单封装
2019/11/13 Javascript
[01:48]2018DOTA2亚洲邀请赛主赛事第二日五佳镜头 VG完美团战逆转TNC
2018/04/05 DOTA
python采集博客中上传的QQ截图文件
2014/07/18 Python
Python二维码生成库qrcode安装和使用示例
2014/12/16 Python
在Python的Tornado框架中实现简单的在线代理的教程
2015/05/02 Python
Python实现简单的多任务mysql转xml的方法
2017/02/08 Python
一个基于flask的web应用诞生(1)
2017/04/11 Python
详解python eval函数的妙用
2017/11/16 Python
浅谈Pandas中map, applymap and apply的区别
2018/04/10 Python
Appium Python自动化测试之环境搭建的步骤
2019/01/23 Python
英国著名的化妆品折扣网站:Allbeauty.com
2016/07/21 全球购物
美国折扣宠物药房:Total Pet Supply
2018/05/27 全球购物
英国运动风奢侈品购物网站:Maison De Fashion
2020/08/28 全球购物
小学新学期教师寄语
2014/01/18 职场文书
二手房购房意向书范本
2014/04/01 职场文书
Nginx同一个域名配置多个项目的实现方法
2021/03/31 Servers
Java基于字符界面的简易收银台
2021/06/26 Java/Android
Nginx静态压缩和代码压缩提高访问速度详解
2022/05/30 Servers