延迟for循环中的更新值

Nic*_*zee 1 html jquery for-loop delay

我想用我的网页更新我的价格.
我目前拥有的:

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

        for ( var i = 0; i <= price; i++ ) {
                $("#price").html("€" + i);              
            }
        });     
    });
Run Code Online (Sandbox Code Playgroud)

我的For循环需要延迟,因此您可以看到价格向上迭代.
任何帮助都表示赞赏!

Rob*_*ker 7

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

increasePrice(0, 200);
Run Code Online (Sandbox Code Playgroud)

这将每20毫秒迭代一次.

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