小程序60秒倒计时
2020-06-09 本文已影响0人
cs大个子女生
html:
<button bindtap="ci_dao" disabled="{{disabled}}">{{dao}}</button> 需要用button标签,设置不可点击
data中定义:
dao: "倒计时", disabled: false,
js:
//倒计时
ci_dao: function () {
var num = 60;
var that = this;
that.setData({
dao: num + "倒计时了",
disabled: true
});
var interval = setInterval(function () {
num = num - 1;
console.log(num)
if (num > 0) {
that.setData({
dao: num + "倒计时了"
});
} else {
clearInterval(interval)
that.setData({
dao: "重新获取",
disabled: false
});
num = 60;
}
}, 1000);
}