您的位置:首页 > 移动开发 > 微信开发

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

2017-11-15 11:34 676 查看






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
})
},

})
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: