0
点赞
收藏
分享

微信扫一扫

小程序获取验证码倒计时功能


分享一段小程序倒计时的代码



Page({

/**
* 页面的初始数据
*/
data: {
timeCountDownTop: "获取验证码",
second: 90,
counting: false
},

getVerifityCode: function() {
var that = this;
if (!that.data.counting) {
wx.showToast({
title: '验证码已发送',
})
//开始倒计时
countDown(that, that.data.second);
}

function countDown(that, count) {
if (count == 0) {
that.setData({
timeCountDownTop: '获取验证码',
counting: false
})
return;
}

that.setData({
counting: true,
timeCountDownTop: count + '秒后重新获取',
second: count
})
setTimeout(function() {
count--;
countDown(that, count);
}, 1000);
}
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function(options) {

},
})


举报

相关推荐

0 条评论