jQuery 需要根据 rowspan 循环下一个元素
好吧,基本上,我有一个像这样设置的表格,但是 元素可以有任意数量的行跨度...
<table width="100%">
<tr class="tablerow0">
<td class="tablecol_0" colspan="4">Content</td>
</tr>
<tr class="tablerow1">
<td class="tablecol_0" rowspan="2">More Content</td>
<td class="tablecol_1" colspan="3">Some More Content</td>
</tr>
<tr class="tablerow2">
<td class="tablecol_1">And Yet More Content</td>
<td class="tablecol_2">Content</td>
<td class="tablecol_3">Content</td>
</tr>
</table>
好吧,所以我想做的是确定行数rowspans 可以像这样完成:
$("td").each(function() {
$(this).attr('rowspan');
});
但是对于每个大于 1 的 rowspans,我需要从每个函数中返回 false。例如,当它找到 rowspan 为 2 的元素时,它不应该继续到下一个元素,因为rowspan 附加到下一个元素。但更重要的是,我需要循环遍历 元素的行跨度。
例如,如果我有这个表设置:
<table width="100%">
<tr class="tablerow0">
<td class="tablecol_0" rowspan="2">Content</td>
<td class="tablecol_1">Content</td>
<td class="tablecol_2">Content</td>
</tr>
<tr class="tablerow1">
<td class="tablecol_1">More Content</td>
<td class="tablecol_2">Some More Content</td>
</tr>
<tr class="tablerow2">
<td class="tablecol_1">And Yet More Content</td>
<td class="tablecol_2">Content</td>
<td class="tablecol_3">Content</td>
</tr>
</table>
那么它需要使用 class="tablerow2"
获取这里的最后一个 因为 rowspan 仅覆盖
tablerow0
和 tablerow1
。
希望您明白我的意思,它需要能够在 元素中循环,并且仅在超出这些
rowspan
数量时执行某些操作表中的 > 元素。行跨度可以超过 2,我只是对其进行简化,以便人们理解我在这里要问的内容。此外,可能有超过 1 个 元素的 rowspan 大于 1,因此它也应该能够知道这一点。我想我需要在这里构建一个 rowspan 数组,并且数组长度将基于每个
rowspan 值。
Well, basically, I have a table set up like so, but <td>
elements can have any number of rowspans...
<table width="100%">
<tr class="tablerow0">
<td class="tablecol_0" colspan="4">Content</td>
</tr>
<tr class="tablerow1">
<td class="tablecol_0" rowspan="2">More Content</td>
<td class="tablecol_1" colspan="3">Some More Content</td>
</tr>
<tr class="tablerow2">
<td class="tablecol_1">And Yet More Content</td>
<td class="tablecol_2">Content</td>
<td class="tablecol_3">Content</td>
</tr>
</table>
Ok, so what I'd like to do is determine the number of rowspans which can be done like so:
$("td").each(function() {
$(this).attr('rowspan');
});
But I need to return false
out of this each function for each rowspan greater than 1. For example, when it finds the element with a rowspan of 2, it should not continue onto the next element, because the rowspan is attached to the next element. BUT MORE IMPORTANTLY, I need to loop through the rowspans for <tr>
elements.
Example, if I have this table setup:
<table width="100%">
<tr class="tablerow0">
<td class="tablecol_0" rowspan="2">Content</td>
<td class="tablecol_1">Content</td>
<td class="tablecol_2">Content</td>
</tr>
<tr class="tablerow1">
<td class="tablecol_1">More Content</td>
<td class="tablecol_2">Some More Content</td>
</tr>
<tr class="tablerow2">
<td class="tablecol_1">And Yet More Content</td>
<td class="tablecol_2">Content</td>
<td class="tablecol_3">Content</td>
</tr>
</table>
Than it will need to get the last <tr>
in here with class="tablerow2"
because the rowspan only covers tablerow0
and tablerow1
.
Hopefully you get what I mean, it needs to be able to loop within the <td>
elements and only do something when the rowspan
quantity has been exceeded for those <tr>
elements in the table. The rowspan can be more than 2, I'm just simplifying this for people to grasp what I'm asking here. Also, there can be more than 1 <td>
element with a rowspan greater than 1 so, it should be able to know this as well. I'm thinking I will need to build an array of rowspans here, and the array length will be based on each <td>
rowspan value.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您还可以将
[rowspan]
更改为[rowspan=2]
以检查特定的 rowspan 值。这是一个演示: http://jsfiddle.net/JyQYW/
更新
这是一个简单的检查示例对于超过
rowspan=2
:新代码会检查以确保向下有足够的行,然后检查最后三行是否影响当前行。
You can also change
[rowspan]
to[rowspan=2]
to check for a specific rowspan value.Here is a demo: http://jsfiddle.net/JyQYW/
Update
Here is a simple example of checking for more than
rowspan=2
:The new code checks to make sure we are enough rows down and then checks if the last three rows are affecting the current one.