dom部分
----------------------------------------------------------------------------------------------
<text wx:if="{{reSend}}" bindtap='countdown'>获取验证码</text>
<text wx:else>{{second}}</text>
data部分
----------------------------------------------------------------------------------------------
data: {
second: 60,
reSend: true
}
js部分
----------------------------------------------------------------------------------------------
countdown: function () {
var nsecond = 60;
var that = this;
var appCount = setInterval(function () {
nsecond -= 1;
that.setData({
second: nsecond+' s',
reSend: false
})
if (nsecond < 1) {
clearInterval(appCount);
//取消指定的setInterval函数将要执行的代码
that.setData({
second: 60,
reSend: true
})
}
}, 1000);
}