Запустите jQuery после завершения функции setInterval

0

У меня есть функция count count, и я хочу запустить некоторый код только после завершения функции count. Есть ли способ сделать это просто?

DEMO http://jsfiddle.net/vyN6V/243/

Текущий код

    var number = 1500;
    var aValue = 300;

    function count(Item) {
        var current = aValue;
        Item.val(aValue += 1);
        if (current < number) {
            setTimeout(function () {
                count(Item)
            }, 0.1);
        }
    }

    count($(".input"));
    // code here should only run when count function is complete

Я пробовал это, безрезультатно

    var number = 1500;
    var aValue = 300;

    function count(Item) {
        var current = aValue;
        Item.val(aValue += 1);
        if (current < number) {
            setTimeout(function () {
                count(Item)
            }, 0.1);
        }
    }

    count(function$(".input"){
      // code here should only run when count function is complete
   });
Теги:

1 ответ

1
Лучший ответ

FIDDLE

var number = 1500;
var aValue = 300;

function count(Item) {
    var current = aValue;
    Item.val(aValue += 1);
    if (current < number) {
        setTimeout(function () {
            count(Item)
        }, 0.1);
    } else {
        $('span').text('code here should only run when function count is complete');
    }
}

count($(".input"));
  • 0
    Спасибо! Примет, когда это позволит мне

Ещё вопросы

Сообщество Overcoder
Наверх
Меню