仿支付宝支付密码输入框功能

上次看到别人说写一个类似支付宝支付密码的输入框效果,今天就想自己写了试试看,大体功能是实现了。

已实现部分:
1. 焦点会随着输入数值往后推移
2. 如果输入的非0-9,则会出现提示
3. 按Backspance回车可以对应格子焦点往前推移
4. 按回车或者点击按钮可以触发按钮点击事件,获得输入值

未完善部分:
1. 在控制输入类型的时候,只有0-9、非0-9以及回车、回删几个键盘事件的区分,不够完善
2. 输入框用的input标签,password类型,会将输入值变成圆点,但是圆点太小不够美观,不知道如何改变圆点大小,考虑是否要画个圆点遮盖

ps:代码不够精简,很多感觉还可以改进精简。


效果图:
这里写图片描述


代码段:

**index.html 主要代码**

<div class="content">
    <div class="title">支付宝支付密码:</div>
    <div class="box"></div>
    <div class="forget">忘记密码?</div>
    <div class="point">请输入6位数字密码</div>
    <button class="getPasswordBtn">一键获取密码</button>
    <div class="errorPoint">请输入数字!</div>

</div>
**reset.css代码**

*{
    padding: 0;
    margin: 0;
}
.content{
    width: 400px;
    height: 50px;
    margin: 0 auto;
    margin-top: 100px;

}
.title{
    font-family: '微软雅黑';
    font-size: 16px;
}
.box{
    width: 
  • 4
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
以下是使用uniapp实现仿微信支付密码输入框的示例代码: ```html <template> <view class="container"> <view class="input-box"> <view v-for="(item, index) in inputList" :key="index" class="input-item" :class="{ 'input-item-active': index === currentIndex }" > <view class="input-dot" v-show="item !== ''"></view> </view> </view> <view class="keyboard"> <view class="keyboard-row" v-for="row in keyboard" :key="row"> <view class="keyboard-item" v-for="key in row" :key="key" @click="handleKeyClick(key)" > {{ key }} </view> </view> </view> </view> </template> <script> export default { data() { return { inputList: ['', '', '', '', '', ''], // 输入框列表 currentIndex: 0, // 当前输入框索引 keyboard: [ ['1', '2', '3'], ['4', '5', '6'], ['7', '8', '9'], ['', '0', '删除'] ] // 键盘布局 }; }, methods: { handleKeyClick(key) { if (key === '删除') { if (this.currentIndex > 0) { this.currentIndex--; this.inputList[this.currentIndex] = ''; } } else { if (this.currentIndex < this.inputList.length) { this.inputList[this.currentIndex] = key; this.currentIndex++; } } } } }; </script> <style> .container { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 100vh; } .input-box { display: flex; justify-content: space-between; width: 300rpx; height: 50rpx; border: 1rpx solid #ccc; border-radius: 4rpx; overflow: hidden; } .input-item { flex: 1; display: flex; align-items: center; justify-content: center; font-size: 24rpx; color: #333; } .input-item-active { background-color: #f5f5f5; } .input-dot { width: 10rpx; height: 10rpx; border-radius: 50%; background-color: #333; } .keyboard { margin-top: 20rpx; } .keyboard-row { display: flex; justify-content: space-between; margin-bottom: 10rpx; } .keyboard-item { display: flex; align-items: center; justify-content: center; width: 100rpx; height: 100rpx; border: 1rpx solid #ccc; border-radius: 4rpx; font-size: 32rpx; color: #333; } </style> ``` 这段代码实现了一个简单的支付密码输入框,包括自定义的输入框样式和键盘布局。用户可以点击键盘上的数字输入密码,点击删除按钮可以删除已输入密码输入密码会在输入框中显示为黑色圆点。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值