【问题标题】:jquery selector needed to select all certain children of parentjquery选择器需要选择父母的所有某些孩子
【发布时间】:2011-04-27 21:54:54
【问题描述】:

我有一个页面,上面有一些表格。在每个表中,第一行是正常的,但其余行具有隐藏类,因此它们不会在加载时显示。在表格第一行的一个单元格中,有一个链接可单击以查看更多详细信息(淡入该表格的隐藏行)。我正在努力让它发挥作用。所以基本上我需要一个选择器来查找与单击的元素在同一个表中的所有隐藏行,以便它们可以淡入。我使用过:

$(.hidden).fadeIn() 

但是因为页面上有不止一个表,它会在所有表中的所有隐藏行中消失,我只想要特定表中的那些。我也用过:

$(this).closest('tr').next(".hidden").fadeIn("slow") 

这是一半,但它只在该表的第一个隐藏行中消失,但如果有多个,那么其余的仍然隐藏。任何帮助将非常感激。谢谢

【问题讨论】:

  • 没有看到你的html标记很难回答

标签: javascript jquery jquery-selectors dom-traversal


【解决方案1】:

试试 -

$(this).closest('tr').nextAll(".hidden").fadeIn("slow"); 

nextAll 的详细文档 -

http://api.jquery.com/nextAll/

【讨论】:

    【解决方案2】:

    是这样,对吧?

    <table>
    <tr>
      <td><span class="show">View more details</span></td>
    </tr>
    <tr class="hidden">...</tr>
    ....
    </table>
    

    然后

        <script type="text/javascript">
            $(document).ready(function() {
              $(".show").click(function() {
                  $(this).closest('table').find('tr.hidden').fadeIn("slow");
              });
            });
       </script>
    

    【讨论】:

      猜你喜欢
      • 2012-10-13
      • 1970-01-01
      • 2011-06-23
      • 1970-01-01
      • 1970-01-01
      • 2011-03-30
      • 1970-01-01
      • 1970-01-01
      • 2011-09-12
      相关资源
      最近更新 更多