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

function refreshBlock() {

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

}

上面的代码每 1 秒自动刷新我页面上 div 标签的内容。

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

function refreshBlock() {
    if ($('#myAccount').html() == 'My Accout') {
        $('#activeItems').load("current_auctions.php");
    };
}

上面的代码,只添加了一个 if 语句,在开始时加载了一次页面,然后停止刷新。如何修复此代码?

4

1 回答 1

2

可能是因为该条件返回错误。

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

正如@nnnnn 所说,很可能是因为“帐户”中的拼写错误。

您可以使用脚本终端在 Chrome 或 Firefox 中轻松调试它。在 Firefox 中您可以安装Firebug,或者在 Chrome 中只需按 Crtl+Shift+J。无论哪种方式,都可以访问 JavaScript 命令行界面并输入:

$('#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.

于 2011-08-17T00:25:11.550 回答