wxml
<button
class="buttonget"
disabled="{{disabled}}"
data-id="2"
bindtap="getBtn"
>
{{time}}
</button>
wxss
/*获取验证码 */
.buttonget {
background-color:
#fff;
display: inline-block;
font-size: 26rpx;
color: rgb(136,
136, 136);
border: 1px
solid #888;
border-radius:
10rpx;
width: 160rpx;
height: 70rpx;
line-height:
70rpx;
position: absolute;
top: 0;
right: 20rpx;
z-index: 2;
padding-right:
0;
padding-left:
0;
margin-top: 10rpx;
}
//验证码倒计时函数
getCode: function (options) {
var that = this;
var currentTime = that.data.currentTime;
that.setData({
time: currentTime + '秒'
})
interval = setInterval(function () {
that.setData({
time: (currentTime - 1) +
'秒'
})
currentTime--;
if (currentTime <=
0) {
clearInterval(interval)
that.setData({
time: '重新获取',
currentTime: 60,
disabled: false
})
}
}, 1000)
},
//验证码倒计时结束