gpt4 book ai didi

javascript - for循环中的settimeout不起作用

转载 作者:行者123 更新时间:2023-11-29 16:20:41 25 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
setTimeout in a for-loop and pass i as value

我正在尝试生成动态数组并将此数组用作循环 .. 但在循环中 settime out 不起作用或功能不起作用。这是我的代码

jQuery(document).ready(function () {
temp = new Array();
generateArray(temp);

function generateArray(temp) {
if (temp.length < 10) {
res = randomXToY(1, 10, 0);
for (var k = 0; k < temp.length; k++) {
if (temp[k] == res) {
var test = 1;
}
}
if (test != 1) {
temp.push(res);
//abc(temp);
}
generateArray(temp);
} else {
for (var z = 0; z < 10; z++) {
tnest(temp[z]);
setTimeout(function () {
removeClassImg(temp[z])
}, 3000);
}
temp = new Array();
generateArray(temp);
}
}

function removeClassImg(result1) {
alert(result1);
$('#img' + result1).fadeTo(12000, 0.1);
return true;
}

function tnest(result) {
alert(result);
$('#img' + result).fadeTo(12000, 1);
return true;
}

function randomXToY(minVal, maxVal, floatVal) {
var randVal = minVal + (Math.random() * (maxVal - minVal));
return typeof floatVal == 'undefined' ? Math.round(randVal) : randVal.toFixed(floatVal);
}
});

函数 removeClassImg 中的警报不起作用..我在 for 循环中使用 settimeout 这不能正常工作。

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com