https://blog.csdn.net/yechaoa/article/details/81985664
微信小程序 定时器setInterval,简单易用
2018年08月23日 18:13:07 yechaoa 阅读数:4142更多
所属专栏: 小程序开发
版权声明:本文为博主原创文章,未经博主允许不得转载。https://blog.csdn.net/yechaoa/article/details/81985664
data:{color:"#ff6f10", disabled: false, getCode:"获取验证码",},
1
2
3
4
5
mini"type="default"plain="true"class='form-code-btn'bindtap='sendCode'style='color:{{color}}; border-color: {{color}};background-color:#FFF;'disabled="{{disabled}}">{{getCode}}
1
sendCode:function(e){varthat =this;vartimes =0vari = setInterval(function(){times++if(times >=60) { that.setData({ color:"#ff6f10", disabled:false, getCode:"获取验证码", }) clearInterval(i) }else{ that.setData({ getCode:"重新获取"+ times +"s", color:"#999", disabled:true}) } },1000)}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
每秒执行一次,并定义一个变量记录
60s之内,设置文字显示、颜色、不可点击
之后,同上,并且清除定时器,即clearInterval(i)