微信小程序,验证码输入框

微信小程序,验证码输入

效果预览

在这里插入图片描述
写了个小程序验证码输入的小demo,用的方法是比较猥琐的隐藏input框,输入内容绑定的方法

wxml代码

<view class="wx-page-content">
  <view class="page-title">输入验证码</view>
  <view class="page-tises"> 已发送4位验证码到<span>+86 {{phone}}</span></view>
  <view class="verificationCode">
    <input type="number" maxlength="4" bindinput="inputValue" focus />
    <view class="{{veCode[0] ? 'activeView' : 0}}">{{veCode[0]}}</view>
    <view class="{{veCode[1] ? 'activeView' : 0}}">{{veCode[1]}}</view>
    <view class="{{veCode[2] ? 'activeView' : 0}}">{{veCode[2]}}</view>
    <view class="{{veCode[3] ? 'activeView' : 0}}">{{veCode[3]}}</view>
  </view>
  <view class="lodingBtn {{veCode.length == 4 ? 'trueLoding' : ''}}">立即登录</view>
  <view class="againTime" wx:if="{{time > 0 }}">重新获取({{time}})</view>
  <view class="againTimeBtn" wx:else bindtap="againTimeBtn">重新获取</view>
</view>

js

Page({
  data: {
    phone:'15654215894',
    veCode: new Array(),
    time: 60
  },
  onLoad() {
    this.againTime()
  },
  inputValue(e) {
    let value = e.detail.value;
    let arr = [...value];
    this.setData({ veCode: arr })
  },
  againTime() {
    let time = this.data.time;
    clearInterval(timing);
    let timing = setInterval(() => {
      if (time <= 0) {
        clearInterval(timing)
      } else {
        time--;
        this.setData({
          time: time
        })
      }
    }, 1000)
  },
  againTimeBtn() {
    this.setData({ time: 60 });
    this.againTime()
  }
})

wxss

view {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}
.wx-page-content {
  padding: 40px;
}
.wx-page-content .page-title {
  font-size: 28px;
  color: #000;
  font-weight: 500;
  margin-bottom: 30px;
}
.wx-page-content .page-tises {
  font-size: 16px;
  color: #000;
}
.wx-page-content .page-tises span {
  color: #ACACAC;
}
.verificationCode {
  overflow: hidden;
  position: relative;
  width: 100%;
  display: flex;
  justify-content: space-between;
  padding-top: 20px;
}
.verificationCode > input {
  width: calc(200%);
  position: absolute;
  left: -100px;
  top: 20px;
  height: 60px;
  background: #e9e9e9;
  opacity: 0;
  font-size: 10px;
}
.verificationCode > view {
  width: 55px;
  border: 1rpx solid #979797;
  height: 60px;
  text-align: center;
  line-height: 60px;
  border-radius: 4px;
  font-size: 30px;
  color: #4DBF6E;
}
.verificationCode .activeView {
  border-color: #4DBF6E;
}
.lodingBtn {
  width: 100%;
  height: 50px;
  margin-top: 20px;
  background: #88c299;
  border-radius: 99px;
  text-align: center;
  line-height: 50px;
  color: #fff;
  font-size: 16px;
}
.trueLoding {
  background: #4DBF6E;
}
.againTime,
.againTimeBtn {
  color: #ACACAC;
  font-size: 12px;
  text-align: center;
  margin-top: 15px;
  text-decoration: underline;
}
.againTimeBtn {
  color: #59ACFF;
}

  • 6
    点赞
  • 27
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值