我有一个基本的计数功能,我希望只在计数功能完成后运行一些代码。有没有办法简单地做到这一点?
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
});
答案 0 :(得分:1)
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"));