简体   繁体   English

jQuery不更新div

[英]jQuery not updating div

I have an element like this: 我有一个像这样的元素:

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

I'm trying 我正在努力

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

I've checked repeatedly, the div foo_233 is being found in firebug and is being shown as hidden. 我反复检查过,在萤火虫中找到了div foo_233并显示为隐藏。 The id is passed on to the javascript function correctly. 该ID已正确传递给javascript函数。 But still the above lines aren't working. 但是上面的代码仍然行不通。 What could be wrong? 有什么事吗 Its very frustrating.. 非常令人沮丧

The space in your selector: 选择器中的空格:

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

Get rid of it: 摆脱它:

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

Presumably, your div IDs should look like "foo_5" but the selector your were building was "foo_ 5" , which is why your if condition never evaluates to true . 大概您的div ID应该看起来像"foo_5"但是您正在构建的选择器是"foo_ 5" ,这就是为什么if条件永远不会评估为true的原因

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM