jQuery秒计数器没有在Fancybox内联中显示

时间:2013-01-12 02:37:28

标签: jquery fancybox

var counter = 5;
var timer = setInterval(function () {
    seconds--;
    $('#regmsg').html('Successful! Message will close in ' + counter);
    if (counter == 0) {
        $.fancybox.close();
        parent.location.reload();
    }
}, 1000);
$.fancybox({
    href: '#regmsg',
    type: 'inline',
    'closeBtn': false
});

我希望时间显示在#regmsg,但它只显示'成功!'而不是消息的其余部分。问题是什么?我该如何解决?

1 个答案:

答案 0 :(得分:0)

seconds更改为counter

var counter = 5;
var timer = setInterval(function () {
    counter--; // <- here
    $('#regmsg').html('Successful! Message will close in ' + counter);
    if (counter == 0) {
        $.fancybox.close();
        parent.location.reload();
    }
}, 1000);

demo