1

我在 Javascript 中有以下代码,有时它只是不工作:

var new_c = 0;
function updateCounter()
{
    var last_c = $("span#counter").text();
    last_c = last_c.replace(",", "");
    last_c = parseInt(last_c);
    if (last_c < new_c)
    {
        last_c++;
        $("span#counter").text(last_c);
    }
}

function refreshCounter()
{
    $("<div>").load("includes/ajax/meter/counter.php",
    {
    }, function() {
        new_c = $(this).text().substr($(this).text().indexOf(";")+1);
        new_c = new_c.trim();
        new_c = parseInt(new_c);
    });
}

window.setInterval("refreshCounter()", 1000);
window.setInterval("updateCounter()", 100);

如果我在执行加载调用后new_crefreshCounter()-function 中发出警报,它有时会返回一条空消息,有时它会返回 page 的内容counter.php,这只是一个数字。

4

0 回答 0