1.setTimeout(function, milliseconds): 在等待指定的毫秒数后执行函数
在等待2秒后。跳转页面
var nav = setTimeout(function() {
wx.navigateTo({
url: '../index/index',
})
}, 2000);
停止执行
clearTimeout()方法停止执行setTimeout()中规定的函数
clearTimeout(nav);
2.setInterval(function, miliseconds): 在每个给定的时间间隔重复给定的函数;
miliseconds:每个执行之间的时间间隔的长度
var timer = setInterval(function(){
var time = new Date();
this.setDate({
time: time
})
},1000)
clearInterval(): 用于停止执行setInterval()方法
clearInterval(timer)