各位大神,我是一个初学者定时器出现乱码怎么办?下面是代码
Page({
onReady: function () {
var that = this
this.interval = setInterval(function () {
that.aB()
}, 1000)
},
aB: function () {
var i = 0
var m = setInterval(function () {
clearInterval(this.interval);
if (i == 100) {
clearInterval(m)
return;
}
i++;
console.log(i)
}, 500)
}
})
乱码??你想问什么
按你的思路的代码
onReady: function () {
var that = this
this.aBinterval = 0
this.interval = setInterval(function () {
that.aB()
}, 1000)
},
aB: function () {
if(this.aBinterval) return;
var i = 0
this.aBinterval = setInterval(function () {
clearInterval(this.interval);
if (i == 100) {
clearInterval(this.aBinterval)
this.aBinterval = 0
return;
}
i++;
console.log(i)
}, 500)
},
i不是按顺序:1,2,3,4,5,6,7,8,9打印的,而是两个计时器叠加出现的