我使用以下代码选择 element1(Selected Table row 1) 和 element2(Selected Table row 2) 之间的所有元素(表行),但它给出了表的所有行,而不是以下两行之间的唯一行。
$("img[alt='Expand']").bind("click", function () {
var elementUntil1 = $(this).parent().parent().parent();
var elementUntil2 = elementUntil1.nextAll("tr.SubClassRow:first")
var betweenElement = $(elementUntil1[0]).nextUntil(elementUntil[0]).andSelf();
});
<table>
<tbody>
<tr class="SubClassRow">
<td style="padding-left: 10px;">
<div class="clickable">
<img alt="Expand" />
</div>
</td>
<td>15-Sep-2001</td>
<td> </td>
<td> </td>
<td> </td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="VehicleDetailRow">
<td style="padding-left: 10px;">
<div class="clickable">
<img alt="hidden" />
</div>
</td>
<td>15-Sep-2001</td>
<td> </td>
<td> </td>
<td> </td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="VehicleDetailRow">
<td style="padding-left: 10px;">
<div class="clickable">
<img alt="hidden" />
</div>
</td>
<td>15-Sep-2001</td>
<td> </td>
<td> </td>
<td> </td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="SubClassRow">
<td style="padding-left: 10px;">
<div class="clickable">
<img alt="Expand" />
</div>
</td>
<td>15-Sep-2001</td>
<td> </td>
<td> </td>
<td> </td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="VehicleDetailRow">
<td style="padding-left: 10px;">
<div class="clickable">
<img alt="hidden" />
</div>
</td>
<td>15-Sep-2001</td>
<td> </td>
<td> </td>
<td> </td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="VehicleDetailRow">
<td style="padding-left: 10px;">
<div class="clickable">
<img alt="hidden" />
</div>
</td>
<td>15-Sep-2001</td>
<td> </td>
<td> </td>
<td> </td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="SubClassRow">
<td style="padding-left: 10px;">
<div class="clickable">
<img alt="Expand" />
</div>
</td>
<td>15-Sep-2001</td>
<td> </td>
<td> </td>
<td> </td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="VehicleDetailRow">
<td style="padding-left: 10px;">
<div class="clickable">
<img alt="hidden" />
</div>
</td>
<td>15-Sep-2001</td>
<td> </td>
<td> </td>
<td> </td>
<td></td>
<td></td>
<td></td>
</tr>
<tr class="VehicleDetailRow">
<td style="padding-left: 10px;">
<div class="clickable">
<img alt="hidden" />
</div>
</td>
<td>15-Sep-2001</td>
<td> </td>
<td> </td>
<td> </td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
</table>