如何在带 ID 的其他行之间查找行,然后添加类
我被我的桌子困住了。我需要创建切换行功能,但我不知道如何在表中查找子行。有人可以帮助我吗?
- 我有很多行的表> 500
- 所有行都有 class="row-1,row-2.....row-600 等"
- 并且所有主行也有 class="parent"
在每个“父”行之间我有 6 行, 所以我需要出于切换/折叠的目的找到父行之间的所有(子)行。并添加带有 id 的类,如上一个父行中所示。
例如:
父级有 class="row-1 父级"
所有子必须有 - class="child-row-1"
默认表
<table id="table">
<tr class="row-1 odd parent">
<th class="column-1">st. 3 - 5</th>
<th class="column-2">Profile</th>
<th class="column-3">Purpose</th>
</tr>
<tr class="row-2 even">
<td class="column-1">Metal Stamp</td>
<td class="column-2">Width</td>
<td class="column-3">Price</td>
</tr>
<tr class="row-3 odd">
<td class="column-1">Circle 3 - 5</td>
<td class="column-2">28-110</td>
<td class="column-3">21500</td>
</tr>
<tr class="row-4 even">
<td class="column-1">Circle 3 - 5</td>
<td class="column-2">115-180</td>
<td class="column-3">20700</td>
</tr>
<tr class="row-5 odd">
<td class="column-1">Cube 3 - 5</td>
<td class="column-2">63-80</td>
<td class="column-3">21500</td>
</tr>
<tr class="row-6 even">
<td class="column-1">Cube 3 - 5</td>
<td class="column-2">100-220</td>
<td class="column-3">20700</td>
</tr>
<tr class="row-7 odd">
<td class="column-1">Line 3 - 5</td>
<td class="column-2">10-50 х 40-200</td>
<td class="column-3">27000</td>
</tr>
</table>
最后它应该看起来像这样:
<table id="table">
<tr class="row-1 odd parent">
<th class="column-1">st. 3 - 5</th>
<th class="column-2">Profile</th>
<th class="column-3">Purpose</th>
</tr>
<tr class="row-2 even child-row-1">
<td class="column-1">Metal Stamp</td>
<td class="column-2">Width</td>
<td class="column-3">Price</td>
</tr>
<tr class="row-3 odd child-row-1">
<td class="column-1">Circle 3 - 5</td>
<td class="column-2">28-110</td>
<td class="column-3">21500</td>
</tr>
<tr class="row-4 even child-row-1">
<td class="column-1">Circle 3 - 5</td>
<td class="column-2">115-180</td>
<td class="column-3">20700</td>
</tr>
<tr class="row-5 odd child-row-1">
<td class="column-1">Cube 3 - 5</td>
<td class="column-2">63-80</td>
<td class="column-3">21500</td>
</tr>
<tr class="row-6 even child-row-1">
<td class="column-1">Cube 3 - 5</td>
<td class="column-2">100-220</td>
<td class="column-3">20700</td>
</tr>
<tr class="row-7 odd child-row-1">
<td class="column-1">Line 3 - 5</td>
<td class="column-2">10-50 х 40-200</td>
<td class="column-3">27000</td>
</tr>
</table>
I'm stuck with my table. I need create toggle rows function, but I have no idea how to find sub rows in table. Can someone help me?
- I have table with many rows > 500
- All Rows have class="row-1,row-2.....row-600 etc"
- And all main rows also have class="parent"
Between each "parent" rows I have 6 rows,
so I need for toggle/collapse purposes find all (sub)rows between parent rows. and add class with id like in previous parent row.
For example:
parent have class="row-1 parent"
all sub must have - class="child-row-1"
default table
<table id="table">
<tr class="row-1 odd parent">
<th class="column-1">st. 3 - 5</th>
<th class="column-2">Profile</th>
<th class="column-3">Purpose</th>
</tr>
<tr class="row-2 even">
<td class="column-1">Metal Stamp</td>
<td class="column-2">Width</td>
<td class="column-3">Price</td>
</tr>
<tr class="row-3 odd">
<td class="column-1">Circle 3 - 5</td>
<td class="column-2">28-110</td>
<td class="column-3">21500</td>
</tr>
<tr class="row-4 even">
<td class="column-1">Circle 3 - 5</td>
<td class="column-2">115-180</td>
<td class="column-3">20700</td>
</tr>
<tr class="row-5 odd">
<td class="column-1">Cube 3 - 5</td>
<td class="column-2">63-80</td>
<td class="column-3">21500</td>
</tr>
<tr class="row-6 even">
<td class="column-1">Cube 3 - 5</td>
<td class="column-2">100-220</td>
<td class="column-3">20700</td>
</tr>
<tr class="row-7 odd">
<td class="column-1">Line 3 - 5</td>
<td class="column-2">10-50 х 40-200</td>
<td class="column-3">27000</td>
</tr>
</table>
in the end it should look like this:
<table id="table">
<tr class="row-1 odd parent">
<th class="column-1">st. 3 - 5</th>
<th class="column-2">Profile</th>
<th class="column-3">Purpose</th>
</tr>
<tr class="row-2 even child-row-1">
<td class="column-1">Metal Stamp</td>
<td class="column-2">Width</td>
<td class="column-3">Price</td>
</tr>
<tr class="row-3 odd child-row-1">
<td class="column-1">Circle 3 - 5</td>
<td class="column-2">28-110</td>
<td class="column-3">21500</td>
</tr>
<tr class="row-4 even child-row-1">
<td class="column-1">Circle 3 - 5</td>
<td class="column-2">115-180</td>
<td class="column-3">20700</td>
</tr>
<tr class="row-5 odd child-row-1">
<td class="column-1">Cube 3 - 5</td>
<td class="column-2">63-80</td>
<td class="column-3">21500</td>
</tr>
<tr class="row-6 even child-row-1">
<td class="column-1">Cube 3 - 5</td>
<td class="column-2">100-220</td>
<td class="column-3">20700</td>
</tr>
<tr class="row-7 odd child-row-1">
<td class="column-1">Line 3 - 5</td>
<td class="column-2">10-50 х 40-200</td>
<td class="column-3">27000</td>
</tr>
</table>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
jQuery 中有一个 nextUntil 方法用于遍历树。实际上,您可以使用很多方法来遍历树,您可以了解有关它们的更多信息
要对所有行执行此操作:
$('.parent').each(..)
(row-nn)
.parent
。jsf 更新。
There is a nextUntil method in jQuery for traversing the tree. Actually there are a bunch of methods you could use for traversing the tree and you can learn more about them here.
To do this for all rows:
$('.parent').each(..)
(row-nn)
(child-row-nn)
to next rows until the next.parent
.Update on jsf.