分享一个PC端六格密码输入框写法

如图。我们一般做商城类的项目不免会用到支付密码输入框,我研究了下并决定发上来,也当作是自己成长路上的一点小小的记录。本次介绍的是基于vue的项目
html:
<template>
<div class='am_payPwd' :id="`ids_${id}`">
<input type="password"
maxlength="1"
@input="changeInput"
@click="changePwd"
v-model="pwdList[i]"
@keyup="keyUp($event)"
@keydown="oldPwdList = pwdList.length"
class="shortInput"
v-for="(v, i) in 6" :key="i">
</div>
</template>
css:
.am_payPwd {
display: inline-block;
width: 242px;
height: 40px;
border: 1px solid #999;
border-radius: 5px;
padding: 10px 0;
position: relative;
margin-left: 1px;
.shortInput {
text-align: center;
font-size: 20px;
float: left;
width: 40px;
height: 20px;
color: #333;
outline: #ff0067;
&:not(:last-child) {
border-right: 1px solid #999;
}
}
}
js:
data () {
return {
pwdList: [],
oldPwdList: [],
isDelete: false,
ipt: ''
}
},
props: {
id: String, // 当一个页面有多个密码输入框时,用id来区分
default: '1'
},
mounted () {
this.ipt = document.querySelectorAll(`#ids_${this.id} .shortInput`)
},
methods: {
keyUp (ev) {
let index = this.pwdList.length
if (!index) return
if (ev.keyCode === 8) {
this.isDelete = true
if (this.oldPwdList === this.pwdList.length) {
if (index === this.pwdList.length) {
this.pwdList.pop()
}
index--
} else {
index > 0 && index--
}
this.ipt[index].focus()
} else if (this.isDelete && index === this.pwdList.length && /^\d$/.test(ev.key)) {
this.isDelete = false
this.pwdList.pop()
this.pwdList.push(ev.key)
this.ipt[this.pwdList.length] && this.ipt[this.pwdList.length].focus()
}
this.$emit('getPwd', this.pwdList.join(''))
},
changePwd () {
let index = this.pwdList.length
index === 6 && index--
this.ipt[index].focus()
},
changeInput () {
let index = this.pwdList.length
let val = this.pwdList[index - 1]
if (!/[0-9]/.test(val)) {
this.pwdList.pop()
return
}
if (!val) {
this.pwdList.pop()
index--
if (index > 0) this.ipt[index - 1].focus()
} else {
if (index <) this.ipt[index].focus()
}
}
}
如有考虑不周的,请指出
分享一个PC端六格密码输入框写法的更多相关文章
- 怎样写一个PC端使用的操盘手软件(用来买卖股票,查看报表,行情)
我们想写一个操盘手软件,对于操盘而言,首先是快,然后是资料尽可能丰富,最好能看到行情,报表什么的.只是windows上写软件看似基础,实际上都不怎么好弄,用C++开发确实可以实现所有功能,估计光研发费 ...
- Supalle-Admin-Layout,一个PC端和手机端都合适用的后台页面模板
Supalle-Admin-Layout主要使用有Vue.Element-UI.layui-icon,Ajax实现采用Fetch(是有这个打算,不过目前是jQuery.). 源码地址:https:// ...
- 分享一个移动端rem布局的适配mixin
/*================================================================ 以下为基于ip5 宽度320做的适配,标准html{font-si ...
- PC端页面适应不同的分辨率的方法 (转载)
原文地址:https://blog.csdn.net/fengzhen8023/article/details/81281117 上周完成一个PC端的项目,对于我这样的小白来说,这个项目里面最大的问题 ...
- JavaScript判断移动端及pc端访问不同的网站
JavaScript判断移动端及pc端访问不同的网站 现在很多网站都是分为两个版本,一个pc端的一个移动端的(响应式除外),针对这两个版本,就需要对访问的设备进行判断,如果是pc,就直接访问pc网站, ...
- 自动识别移动端还是PC端
平时在开发中经常会遇到这样的需求,除了开发PC端之外,还会同时开发移动端.对于简单的页面,可以使用bootstrap之类的框架实现响应式页面,可是当页面很复杂的时候,就需要开发一个移动端页面,一个PC ...
- CoCos2dx开发:PC端调试运行正常但打包apk文件后在手机上点击闪退
记:今天调试时出现的一个PC端调试运行正常,但打包apk文件后在手机上点击闪退的问题. 可能在不同的情况条件下,会有不同的原因导致apk安装后闪退问题.拿android studio等软件来说,开发安 ...
- 自适应PC端网页制作使用REM
做一个PC端的网页,设计图是1920X1080的. 要在常见屏上显示正常(比例正确可) 1280X720 1366X768 1440X900 1920X1080 使用了几种办法 1.内容在一屏内显示的 ...
- Unity输出PC端(Windows) 拖拽文件到app中
需求:给策划们写一个PC端(Window)的Excel导表工具.本来用OpenFile打开FileExplorerDialog后让他们自己选择想要添加的Excel文件就行了,结果有个需求是希望能拖拽E ...
随机推荐
- LDAP入门与OpenLDAP使用配置
LDAP入门与OpenLDAP使用配置 1.LDAP简介 LDAP(轻量级目录访问协议,Lightweight Directory Access Protocol)是实现提供被称为目录服务的信息服务. ...
- Netty-EventLoop
1. public interface EventLoop extends EventExecutor, EventLoopGroup 2. public interface EventExecuto ...
- 03_Redis数据类型(List)
[List类型] Redis采用的是LinkedList. ArrayList: 数组存储.查询快,增删慢. LinkedList:链表存储.增删快,查询慢,查询两端快. Redis的list内部采用 ...
- jdk时区相差8小时
设置JVM的默认时区为东八区(北京时间)在下面四个目录(jre6\lib\zi\Etc.jre6\lib\zi.jdk1.6.0_18\jre\lib\zi\Etc.jdk1.6.0_18\jre\l ...
- 1.6 WEB API NET CORE 使用Redis
一.Redis安装 https://www.cnblogs.com/cvol/p/9174078.html 二.新建.net core web api程序 选webapi 或者应用程序都可以 三.使用 ...
- Intel® Manager for Lustre* software(一)
Intel® Manager for Lustre* software Installation 软件安装指导目录: 安装IML(Intel® Manager for Lustre* software ...
- SQA1
客观地验证软件项目产品和工作是否遵循恰当的标准.步骤和需求. 2.将软件质量保证工作及结果通知给相关组别和个人.
- cocos2d-x3.1 下实现相似Android下ExpandListView的效果
在左Android開始有SDK提供ExpandListView的可扩展列表,而在iOS下有很多第三方做好的Demo,这里我是參照iOS下RATreeView这个第三方库实现的. 本文代码:须要在3.1 ...
- hiho 第155周 任务分配
最小路径覆盖会超时: 贪心思路: 按照开始时间排序,然后根据结束时间,维护一个以结束时间的单调递增的队列,每次与最快结束的任务进行比较即可: /* #include <cstdio> #i ...
- 梯度下降(HGL)
线性回归:是利用数理统计中回归分析,来确定两种或两种以上变量间相互依赖的定量关系的一种统计分析方法. 对于一般训练集: 参数系统为: 线性模型为: 损 ...