我试图循环遍历 $('.fore-col') 并每次向上递增时迭代 api 调用变量的索引位置。从 7 开始,增加 8,直到 40 的位置。当我运行这段代码时,它陷入了“永远循环”,我相信并且没有停止在 40 的索引位置。在我拉动之前的最高计数插头刚刚超过20k。
任何帮助将不胜感激!
url: forecastURL,
method: "GET"
}).then(function(res) {
console.log(res);
$(".fore-col").each(function() {
for (let i = 7; i < 40; i + 8) {
let date = res.list[i].dt_txt;
let icon =
"https://openweathermap.org/img/wn/" +
res.list[i].weather +
".png";
let temp = res.list[i].main.temp;
let humid = res.list[i].main.humidity;
console.log(date, icon, temp, humid);
}
});
```
enter code here
最佳答案
for (let i = 7; i < 40; i + 8)
应该是
for (let i = 7; i < 40; i = i + 8)
关于javascript - 双循环陷入永远循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59781750/