基于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 相关文章推荐
利用javascript实现一些常用软件的下载导航
Aug 03 Javascript
Javascript学习笔记二 之 变量
Dec 15 Javascript
JS限制上传图片大小不使用控件在本地实现
Dec 19 Javascript
JS连接SQL数据库与ACCESS数据库的方法实例
Nov 21 Javascript
JavaScript之AOP编程实例
Jul 17 Javascript
JQuery EasyUI的使用
Feb 24 Javascript
JS在一定时间内跳转页面及各种刷新页面的实现方法
May 26 Javascript
JavaScript 拖拽实例代码
Sep 21 Javascript
Asp.Net之JS生成分页条的方法
Nov 23 Javascript
Javascript实现信息滚动效果
May 18 Javascript
easyui简介_动力节点Java学院整理
Jul 14 Javascript
js实现可以点击收缩或张开的悬浮窗
Sep 18 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
星际争霸教主Flash的ID由来:你永远不会知道他之前的ID是www!
2019/01/18 星际争霸
探讨捕获php错误信息方法的详解
2013/06/09 PHP
ThinkPHP之foreach标签使用概述
2014/06/30 PHP
如何使用PHP给图片加水印
2016/10/12 PHP
CSS和JS标签style属性对照表(方便js开发的朋友)
2010/11/11 Javascript
jQuery 源码分析笔记(3) Deferred机制
2011/06/19 Javascript
JS刷新框架外页面七种实现代码
2013/02/18 Javascript
Extjs实现进度条的两种便捷方式
2013/09/26 Javascript
js中生成map对象的方法
2014/01/09 Javascript
javascript模拟post提交隐藏地址栏的参数
2014/09/03 Javascript
js实现鼠标悬停图片上时滚动文字说明的方法
2015/02/17 Javascript
Bootstrap每天必学之前端开发框架
2015/11/19 Javascript
jquery实现删除一个元素后面的所有元素功能
2015/12/21 Javascript
JavaScript编程中实现对象封装特性的实例讲解
2016/06/24 Javascript
javascript判断firebug是否开启的方法
2016/11/23 Javascript
JS排序算法之希尔排序与快速排序实现方法
2017/12/12 Javascript
微信小程序如何获取群聊的openGid以及名称详解
2019/07/17 Javascript
微信域名检测接口调用演示步骤(含PHP、Python)
2019/12/08 Javascript
利用Python获取赶集网招聘信息前篇
2016/04/18 Python
使用apidoc管理RESTful风格Flask项目接口文档方法
2018/02/07 Python
python文本数据相似度的度量
2018/03/12 Python
Python使用selenium实现网页用户名 密码 验证码自动登录功能
2018/05/16 Python
设置python3为默认python的方法
2018/10/31 Python
Python类装饰器实现方法详解
2018/12/21 Python
使用django的ORM框架按月统计近一年内的数据方法
2019/07/18 Python
Python3.6实现根据电影名称(支持电视剧名称),获取下载链接的方法
2019/08/26 Python
python 动态迁移solr数据过程解析
2019/09/04 Python
Python标准库itertools的使用方法
2020/01/17 Python
python 可视化库PyG2Plot的使用
2021/01/21 Python
Black Halo官方网站:购买连衣裙、礼服和连体裤
2018/06/13 全球购物
日语翻译个人求职的自我评价
2013/10/14 职场文书
经销商会议欢迎词
2014/01/11 职场文书
优秀经理事迹材料
2014/02/01 职场文书
运动会加油口号
2014/06/07 职场文书
煤矿开采专业求职信
2014/07/08 职场文书
讲文明知礼仪演讲稿
2014/09/13 职场文书