加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 资源网站 > 资源 > 正文

微信小程序验证码获取倒计时

发布时间:2020-12-14 19:49:34 所属栏目:资源 来源:网络整理
导读:wxml js data:{ disabled: false,code: '获取验证码',},goGetCode:function(){ var that = this; var time = 60; that.setData({ code: '60秒后重发',disabled: true }) var Interval = setInterval(function() { time--; if (time>0){ that.setData({ code:

wxml

js

data:{
    disabled: false,code: '获取验证码',},goGetCode:function(){
    var that = this;
    var time = 60;
    that.setData({
      code: '60秒后重发',disabled: true
    })
    var Interval = setInterval(function() {
      time--;
      if (time>0){
        that.setData({
          code: time + '秒后重发'
        })
      }else{
        clearInterval(Interval);
        that.setData({
          code: '获取验证码',disabled: false
        })
      }
    },1000)

}

wxss

button{  
  width:260rpx;
  height:80rpx; 
  padding: 10rpx 0;
  color: #000;
  line-height: 50rpx; 
  font-size: 32rpx;
  color: #fff;
  background: green;
} 
button[disabled]:not([type]){
 background: red; 
  color: #fff;   
}

wxml

js

data:{
    disabled: false,1000)

}

wxss

button{  
  width:260rpx;
  height:80rpx; 
  padding: 10rpx 0;
  color: #000;
  line-height: 50rpx; 
  font-size: 32rpx;
  color: #fff;
  background: green;
} 
button[disabled]:not([type]){
 background: red; 
  color: #fff;   
}

主看部分wxml

全部