html:
<button class="buttonget" disabled='{{disabled}}' data-id="2" bindtap="getVerificationCode">{{title}}</button>
js:
var interval = null
Page({
data: {
title: '获取验证码',
currentTime: 5
},
//倒计时
countDown: function (options) {
var that = this;
var currentTime = that.data.currentTime
interval = setInterval(function () {
currentTime--;
that.setData({
title: currentTime + '秒',
disabled: false,
})
if (currentTime <= 0) {
clearInterval(interval)
that.setData({
title: '重新获取',
currentTime: 5,
disabled: false
})
}
}, 1000)
},
clickGetVerCode() {
this.countDown();//倒计时
var that = this
that.setData({
disabled: true
})
},
})