商城系統(tǒng) 注冊

小程序驗證碼倒計時獲取方式

2020-09-27|HiShop
導讀:小程序驗證碼倒計時是小程序倒計時功能很常見的一種,輸入手機號等待驗證碼的倒計時,那么這種形式要怎么獲取呢?...

 

小程序驗證碼倒計時是小程序倒計時功能很常見的一種,輸入手機號等待驗證碼的倒計時,那么這種形式要怎么獲取呢?

小程序驗證碼倒計時獲取方式

.wxml

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

.js

小程序驗證碼倒計時獲取方式

var interval = null //倒計時函數(shù)
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;
}

 
HiShop小程序工具提供多類型商城/門店小程序制作,可視化編輯 1秒生成5步上線。通過拖拽、拼接模塊布局小程序商城頁面,所看即所得,只需要美工就能做出精美商城。
更多小程序開發(fā)案例,盡在:http://descansotropical.com/xiaocx/kaifa.html   

電話咨詢 預約演示 0元開店