最近開始接觸微信小程序,會記錄一些相關的小功能——例如這次是點擊【獲取驗證碼】按鈕出現的倒計時效果。
原文: 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; }