支付密码框

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

1、样式表

 1  .wrap{
 2             margin: 10px auto;
 3             width: 329px;
 4             height: 640px;
 7             padding-top: 200px;
 8         }
 9         .inputBoxContainer{
10             width: 240px;
11             height: 50px;
12             margin: 0 auto;
13             position: relative;
14         }
15         .inputBoxContainer .bogusInput{
16             width: 100%;
17             height: 100%;
18             border: #c3c3c3 1px solid;
19             border-radius: 7px;
20             -moz-border-radius: 7px;
21             -webkit-border-radius: 7px;
22             overflow: hidden;
23             position: absolute;
24             z-index: 0;
25         }
26         .inputBoxContainer .realInput{
27             width: 100%;
28             height: 100%;
29             position: absolute;
30             top:0;
31             left: 0;
32             z-index: 1;
33             filter:alpha(opacity=0);
34             -moz-opacity:0;
35             opacity:0;
36         }
37         .inputBoxContainer .bogusInput input{
38             padding: 0;
39             width: 16.3%;
40             height: 100%;
41             float:left;
42             background: #ffffff;
43             text-align: center;
44             font-size: 20px;
45             border: none;
46             border-right: #C3C3C3 1px solid;
47         }
48         .inputBoxContainer .bogusInput input:last-child{
49             border: none;
50         }
51         .confirmButton{
52             width: 240px;
53             height: 45px;
54             border-radius: 7px;
55             -moz-border-radius: 7px;
56             -webkit-border-radius: 7px;
57             background: #f4f4f4;
58             border: #d5d5d5 1px solid;
59             display: block;
60             font-size: 16px;
61             margin: 30px auto;
62             margin-bottom: 20px;
63         }
64         .showValue{
65             width: 240px;
66             height: 22px;
67             line-height: 22px;
68             font-size: 16px;
69             text-align: center;
70             margin: 0 auto;
71         }

2、HTML代码

 1 <div class="wrap">
 2     <div class="inputBoxContainer" id="inputBoxContainer">
 3         <input type="text" class="realInput"/>
 4         <div class="bogusInput">
 5             <input type="password" maxlength="6" disabled/>
 6             <input type="password" maxlength="6" disabled/>
 7             <input type="password" maxlength="6" disabled/>
 8             <input type="password" maxlength="6" disabled/>
 9             <input type="password" maxlength="6" disabled/>
10             <input type="password" maxlength="6" disabled/>
11         </div>
12     </div>
13     <button id="confirmButton" class="confirmButton">查看</button>
14     <p class="showValue" id="showValue"></p>
15 </div>

3、js代码控制逻辑效果

 1    (function(){
 2         var container = document.getElementById("inputBoxContainer");
 3          boxInput = {
 4             maxLength:"",
 5             realInput:"",
 6             bogusInput:"",
 7             bogusInputArr:"",
 8             callback:"",
 9             init:function(fun){
10                 var that = this;
11                 this.callback = fun;
12                 that.realInput = container.children[0];
13                 that.bogusInput = container.children[1];
14                 that.bogusInputArr = that.bogusInput.children;
15                 that.maxLength = that.bogusInputArr[0].getAttribute("maxlength");
16                 that.realInput.oninput = function(){
17                     that.setValue();
18                 }
19                 that.realInput.onpropertychange = function(){
20                     that.setValue();
21                 }
22             },
23             setValue:function(){
24                 this.realInput.value = this.realInput.value.replace(/\D/g,"");
25                 console.log(this.realInput.value.replace(/\D/g,""))
26                 var real_str = this.realInput.value;
27                 for(var i = 0 ; i < this.maxLength ; i++){
28                     this.bogusInputArr[i].value = real_str[i]?real_str[i]:"";
29                 }
30                 if(real_str.length >= this.maxLength){
31                     this.realInput.value = real_str.substring(0,6);
32                     this.callback();
33                 }
34             },
35             getBoxInputValue:function(){
36                 var realValue = "";
37                 for(var i in this.bogusInputArr){
38                     if(!this.bogusInputArr[i].value){
39                         break;
40                     }
41                     realValue += this.bogusInputArr[i].value;
42                 }
43                 return realValue;
44             }
45         }
46     })()
47     boxInput.init(function(){
48         getValue();
49     });
50     document.getElementById("confirmButton").onclick = function(){
51         getValue();
52     }
53     function getValue(){
54         document.getElementById("showValue").innerText = boxInput.getBoxInputValue();
55     }

4.实现的效果

时间: 2024-08-02 21:55:23

支付密码框的相关文章

vue,一路走来(14)--短信验证码框的实现(类似支付密码框)

由于项目的扩展,新增了很多功能,今天谈一下短信验证码框的实现. 思路:每个小方框其实就是单独的每一个input标签(叫假input标签),每个长度为1,然后上面再写一个大的input标签(叫真实input标签),提高层级定位在上方,最大长度为6,然后将上方真实input标签的值传给每一个单独的假input标签. <div class="phonenum-show"> <div class="getback-title">收回剩余礼金 <

iOS密码框的实现方式

说一下密码加密的实现方式 效果图: 实现方式: 主要说一下密码框的实现,这个密码框中间的四个数字其实是4个 UITextField ,然后通过键盘删除键 和TextFiled 的协议shouldChangeCharactersInRange.来判断输入的位置,代码如下: 直接上代码: // //  IDSGameRoomSecretView.h // //  Created by levi.duan on 2017/7/18. //  Copyright ? 2017年 Near. All ri

实现密码框默认文字效果实例代码

实现密码框默认文字效果实例代码:大家都知道很多文本框在默认情况下都有默认的提示文本,例如"请输入姓名"之类的语言,当点击文本框的时候,会清除提示语,比较人性化.但是在密码框中实现此效果可能就有点麻烦了,因为密码框不是以明文显示的,下面就介绍一下代码实例解决此问题.代码如下: <!DOCTYPE html> <html> <head> <meta charset=" utf-8"> <meta name="

Android 判断EditView是否为密码框

最近在做项目的时候需自动判断,一个登陆页面中EditView是否为密码框,我们可以使用inPutType属性来判断,我们可以利用getInputType()来判断,getInputType == 129时EditView就是一个密码框.

iOS密码框实现(二)取消确定按钮

由于将确定按钮去掉了,所以需要重新修改下代码,当输入第四个数字时,自动进入房间. iOS 密码框效果图: 实现方式: 首先声明一个block初始化方法,因为这只是个框框,并不需要处理网络请求等等,需要提供一个block给调用方,调用方利用block 去拿到密码,利用密码做一些开房间等操作. 利用计时器通过0.2秒来看清输入第四位密码,用户输入4位密码后自动进入下一步操作. 1.头文件需要定义: @classIDSGameRoomSecretView; typedefvoid(^selfhandl

Silverlight 密码框 Focus

在做一个例子是需要运行起来后焦点默认设置在密码框上,在网上查了资料 自己找到一种方法,此方法在oob模式下管用 public Login() { InitializeComponent(); txtLoginName.Text = "admin"; // 设置焦点在密码框上 Dispatcher.BeginInvoke(() => { txtLoginPwd.Focus(); }); } 网上找到的另一种方法 1.想在Silverlight首次启动让某个文本框获取焦点,使用Loa

wordpress登录密码框明文显示最后一个输入的字符

wordpress登录密码框明文显示最后一个输入的字符 (function(a){a.fn.dPassword=function(c){var e={interval:200,duration:1000,replacement:"%u25CF",prefix:"password_",debug:false};var d=a.extend(e,c);var b=new Array();var f=new Array();a(this).each(function(){

WPF文本框密码框添加水印效果

WPF文本框密码框添加水印效果 来源: 阅读:559 时间:2014-12-31 分享: 0 按照惯例,先看下效果 文本框水印 文本框水印相对简单,不需要重写模板,仅仅需要一个VisualBrush   和触发器验证一下Text是否为空即可. 上代码: <TextBox Name="txtSerachDataName" Width="120" Height="23" Grid.Column="3" Grid.Row=&q

[原] Android 自定义View 密码框 例子

遵从准则 暴露您view中所有影响可见外观的属性或者行为. 通过XML添加和设置样式 通过元素的属性来控制其外观和行为,支持和重要事件交流的事件监听器 详细步骤见:Android 自定义View步骤 样子 支持的样式 可以通过XML定义影响外边和行为的属性如下 边框圆角值,边框颜色,分割线颜色,边框宽度,密码长度,密码大小,密码颜色 <declare-styleable name="PasswordInputView"> <attr name="border