Mini Program: Code to implement click countdown

不言
Release: 2018-08-10 15:44:02
Original
3067 people have browsed it

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

})
Copy after login
<button disabled=&#39;{{disabled}}&#39; data-id="2" bindtap="getVerificationCode">
{{time}}
</button>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!