Home  >  Article  >  WeChat Applet  >  Mini Program: Code to implement click countdown

Mini Program: Code to implement click countdown

不言
不言Original
2018-08-10 15:44:023084browse

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: &#39;重新发送&#39;,
          currentTime:61,
          disabled: false   
        })
      }
    }, 100)  
  },
  getVerificationCode(){
    this.getCode();
    var that = this
    that.setData({
      disabled:true
    })
  },

})
<button disabled=&#39;{{disabled}}&#39; 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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn