The content of this article is about the mini program: the code to implement click countdown has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.
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 }) }, })
<button disabled='{{disabled}}' data-id="2" bindtap="getVerificationCode"> {{time}} </button>
Related recommendations:
Mini Program Component: Introduction to Chat Session Component (with code)
Mini program interacts with the background Implementation (with code)
The above is the detailed content of Mini Program: Code to implement click countdown. For more information, please follow other related articles on the PHP Chinese website!