js微信小程序-定时器

 

index.js

 

 

function countdown(that) {
var second = that.data.second
if (second == 0) {
// console.log("Time Out...");
that.setData({
showView:true,
second: 60
});
return;
}
var time = setTimeout(function () {
that.setData({
second: second - 1
});
countdown(that);
}
, 1000)
}

Page({
data: {
showView: true,
second:''
},
onLoad: function (options) {

showView: (options.showView == "true" ? true : false)
},
onChangeShowState: function () {
var that = this;
that.setData({
showView: (!that.data.showView),
second:60

})
countdown(this);
}
});

 

 

index.wxml


 
   
 

你可能感兴趣的:(js微信小程序-定时器)