微信小程序【獲取驗證碼】倒計時效果


最近開始接觸微信小程序,會記錄一些相關的小功能——例如這次是點擊【獲取驗證碼】按鈕出現的倒計時效果。

原文: http://blog.csdn.net/Wu_shuxuan/article/details/78539075  感謝

.wxml

   <button class="buttonget" disabled='{{disabled}}' data-id="2" bindtap="getVerificationCode">
            {{time}}
        </button>

.js

var interval = null //倒計時函數
Page({
  data: {
    date: '請選擇日期',
    fun_id: 2,
    time: '獲取驗證碼', //倒計時 
    currentTime: 60
  },
  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: 60,
          disabled: false
        })
      }
    }, 1000)
  },
  getVerificationCode() {
    this.getCode();
    var that = this
    that.setData({
      disabled: true
    })
  },

})

.wxss

.buttonget
{  
   margin-right: 250rpx;
   width:110rpx;
   height:55rpx;
   color: #20B6C5;
   line-height: 50rpx;
   font-size: 25rpx;
   border:1rpx solid #20B6C5;
}

/*隱藏Button按鈕本身的邊框*/

button[class="buttonget"]::after {
  border: 0;
} 

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM