【问题标题】:Exclude multiple elements in .not, including $this排除 .not 中的多个元素,包括 $this
【发布时间】:2014-08-17 22:14:26
【问题描述】:

以下隐藏所有表行,不包括类.accordion.course_header 的行。

  $('#course_list').find("tr").not('.accordion, .course_header').hide();

如何排除$(this).next("tr") 表格行?假设this 是刚刚被点击的tr

详细信息

我正在使用this solution 制作具有手风琴效果的桌子。使用原样的解决方案,如果我单击一行,它的子项将保持展开状态。请注意,当您单击一行 in the jsfiddle 时,它会正确展开子项,但我希望它在再次单击同一行时关闭子项。

我目前拥有的:

var $course_list = $('#course_list');
$course_list.find("tr").not('.accordion, .course_header').hide();
$course_list.find("tr").eq(0).show();

$course_list.find(".accordion").click(function(){
   $course_list.find("tr").not('.accordion, .course_header').hide();
   $(this).next("tr").fadeToggle('fast');
});

这是表格布局:

<table id="course_list">
  <thead>
    <tr class="course_header">
      <th>Date</th>
      <th>Presenter</th>
      <th>Title</th>
     </tr>
  </thead>
  <tbody>
    <tr class="accordion">
      <td>09.26.14</td>
      <td>Arthur Dent</td>
      <td>Example Course</td>
    </tr>
    <tr>
      <td colspan="4">
        COURSE DETAILS GO HERE
      </td>
    </tr>

    <tr class="accordion">
      <td>09.30.14</td>
      <td>Winston Smith</td>
      <td>Another Example</td>
    </tr>
    <tr>
      <td colspan="4">
        COURSE DETAILS GO HERE
      </td>
    </tr>
  </tbody>
</table>

【问题讨论】:

    标签: jquery html


    【解决方案1】:

    您是否尝试将其附加到链中:

    var next = $(this).next("tr");
    $course_list.find("tr").not('.accordion, .course_header').not(next).hide();
    

    【讨论】:

    • 您的解决方案似乎符合我的要求,但现在我才意识到我问错了问题:)。我实际上想忽略$(this).next("tr")
    • 原来您的解决方案也适用于该特定问题:.not($(this).next("tr"))。你能用那个更新你的答案,我会接受吗?你肯定让我走上了正轨。
    • 是的,刚刚提供了上面的解决方案 :)
    猜你喜欢
    • 1970-01-01
    • 2012-03-21
    • 2018-12-03
    • 2013-04-13
    • 1970-01-01
    • 2014-03-17
    • 1970-01-01
    • 2022-01-16
    • 2012-05-01
    相关资源
    最近更新 更多