您的位置:首页 > 移动开发 > 微信开发

微信小程序-定时器

2017-02-21 11:35 183 查看


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

<view class="page">

  <view>

    <button bindtap="onChangeShowState">{{showView?'我是你大爷':second}}</button>

  </view>

</view>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: