gpt4 book ai didi

jquery - 在 for 循环中延迟更新值

转载 作者:行者123 更新时间:2023-11-28 04:01:01 25 4
gpt4 key购买 nike

我想在我的网页上更新我的价格,用一些眼药水。
我目前拥有的:

$(document).ready(function() {
$("#table1").fadeIn(1000, function myLoop()
{
var price = 60;

for ( var i = 0; i <= price; i++ ) {
$("#price").html("€" + i);
}
});
});

我的 For 循环需要延迟,以便您可以看到价格向上迭代。
感谢您的帮助!

最佳答案

function increasePrice(i, max) {
setTimeout(function () {
$("#price").html("€" + i);
i++;
if (i <= max) {
increasePrice(i, max);
}
}, 20);
}

increasePrice(0, 200);

这将每 20 毫秒迭代一次。

演示:http://jsfiddle.net/robschmuecker/78cWu/

关于jquery - 在 for 循环中延迟更新值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24842490/

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