微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

微信小程序实现验证码获取倒计时的效果

这篇文章主要为大家详细介绍了微信小程序实现验证码获取倒计时效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下

本文实例为大家分享微信小程序实现获取验证码倒计时效果的具体代码,供大家参考,具体内容如下

wxml

<button disabled='{{disabled}}' data-id=2 bindtap=getVerificationCode>
{{time}}
</button>

js

var interval = null //倒计时函数
Page({
 data: {
 date:'请选择日期',
 fun_id:2,
 time: '获取验证码', //倒计时 
 currentTime:61
 }, 
 getCode: function (options){
 var that = this;
 var currentTime = that.data.currentTime
 interval = setInterval(function () {
  currentTime--;
  that.setData({
  time: currentTime+'秒'
  })
  if (currentTime <= 0) {
  clearInterval(interval)
  that.setData({
   time: '重新发送',
   currentTime:61,
   disabled: false 
  })
  }
 }, 100) 
 },
 getVerificationCode(){
 this.getCode();
 var that = this
 that.setData({
  disabled:true
 })
 },

})

原文地址:https://www.jb51.cc/weapp/1202220.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。