开发者

why does my jQuery auto-refresh stop working if I add in a if statement?

window.onload = setupRefresh;
function setupRefresh() {
    setInterval("refreshBlock();", 1000);
}

function refreshBlock() {

    $('#activeItems').load("current_auctions.php");

}

the above code automatically refreshes the content of a div tag on my page every 1 second.

window.onload = setupRefresh;
function setupRefresh() {
    setInterval("refreshBlock();", 1000);
}

function refreshBlock() {
    if 开发者_如何学编程($('#myAccount').html() == 'My Accout') {
        $('#activeItems').load("current_auctions.php");
    };
}

The above code, which only has the addition of an if statement, loads up the page once in the beginning, and then ceases to refresh. How can I fix this code?


Probably because that conditional is returning false.

if ($('#myAccount').html() == 'My Accout') {

Quite likely because of the typo in 'Accout', as @nnnnn says.

You can debug this quite easily in Chrome or Firefox by using a script terminal. In Firefox you could install Firebug or in Chrome just press Crtl+Shift+J. Either way get to a JavaScript command-line interface and enter:

$('#myAccount').html() == 'My Accout'

In your page. You'll see it return either true or false. If it's false you can then easily tweak that condition until it's true where you're expecting.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜