大家好,又见面了,我是你们的朋友全栈君。如果您正在找激活码,请点击查看最新教程,关注关注公众号 “全栈程序员社区” 获取激活教程,可能之前旧版本教程已经失效.最新Idea2022.1教程亲测有效,一键激活。
Jetbrains全家桶1年46,售后保障稳定
type==1是循环添加settimout,type==2是循环终止clearTimeout
第一种,建议
timeOut=[];
shutterAnalysis(type){
if(type == 1) {
//添加的方法
for (let i = 0; i < 10; i++) {
that.timeOut[i] = setTimeout(e=> {
console.log("我添加了");
}, i * 2000);
}
}else {
//清除的方法
for (var j = 0; j < 10; j++) {
if (this.timeOut[j] != undefined) {
clearTimeout(this.timeOut[j]);
}
}
}
}
第二种
timeOut=[];
shutterAnalysis(type){
if(type == 1) {
//添加的方法
for (var i = 0; i < 10; i++) {
(function (i) {
that.timeOut[i] = setTimeout(function () {
console.log("我添加了");
}, i * 2000);
})(i);
}
}else {
//清除的方法
for (var j = 0; j < 10; j++) {
if (this.timeOut[j] != undefined) {
clearTimeout(this.timeOut[j]);
}
}
}
}
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/226836.html原文链接:https://javaforall.net