【问题标题】:jQuery not updating divjQuery不更新div
【发布时间】:2009-06-25 16:30:51
【问题描述】:

我有一个这样的元素:

<div id="foo_<?php echo $id;?>" class="hidden"></div>

我在努力

if ($("#foo_ " + id).is(':hidden'))
{
    //stuff
    $("#foo_ " + id).html(html).slideDown('fast');
}

我反复检查,在 firebug 中找到了 div foo_233 并显示为隐藏。 id 正确传递给 javascript 函数。但是以上几行仍然不起作用。有什么问题?很郁闷..

【问题讨论】:

  • $("#foo_ " + id).is(':hidden') == true 吗?

标签: javascript jquery html ajax


【解决方案1】:

选择器中的空格:

if ($("#foo_ " + id).is(':hidden'))
{
    //stuff
    $("#foo_ " + id).html(html).slideDown('fast');
}

摆脱它:

if ($("#foo_" + id).is(':hidden'))
{
    //stuff
    $("#foo_" + id).html(html).slideDown('fast');
}

大概,您的 div ID 应该看起来像 "foo_5",但您正在构建的选择器是 "foo_ 5",这就是为什么您的 if 条件永远不会评估为 true

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多