在JQuery中从当前到结束进行筛选

Filter from current to the end in JQuery

本文关键字:结束 筛选 JQuery      更新时间:2024-03-14

如何在JQuery中将结果从当前元素过滤到末尾?

有一些过滤器:

  • 已打开;

  • 已关闭;

  • 其他;

  • 已完成;

例如,我需要这些行从"Closed"到"Finished"显示,包括它们之间按过滤器顺序显示的所有行,这些行按随机顺序显示:

<tr class='row' data-row-choice="Opened">
<tr class='row' data-row-choice="Closed">
<tr class='row' data-row-choice="SomethingElse">
<tr class='row' data-row-choice="Opened">
<tr class='row' data-row-choice="Finished">

我无法理解这种行为的逻辑。

编辑:为我的问题添加了一些解释。

您需要使用.nextUntil()和attribute equals选择器以及.addSelf().add()来添加开始和结束元素:

$('[data-row-choice="Closed"]')
  .nextUntil('[data-row-choice="Finished"]')//gets all inbetween element
     .andSelf()//add start element
       .add('[data-row-choice="Finished"]')//add end element
         .show();

工作演示

使用.nextUntil()

$(".row[data-row-choice='Closed']").nextUntil(".row[data-row-choice='Finished']").show();

在fiddle示例下结账

`http://jsfiddle.net/n38emL5m/`