Javascript 计数体';在两个影院之间`
我有一个简单的表,其结构如下:Javascript 计数体';在两个影院之间`,javascript,jquery,html-table,Javascript,Jquery,Html Table,我有一个简单的表,其结构如下: <table> <thead> <tr> <td>Some info</td> <td>Some info</td> <td>Some info</td> </tr> </thead> <tbody&g
<table>
<thead>
<tr>
<td>Some info</td>
<td>Some info</td>
<td>Some info</td>
</tr>
</thead>
<tbody>
<tr>
<td>Some info</td>
<td>Some info</td>
<td>Some info</td>
</tr>
</tbody>
<tbody>
<tr>
<td>Some info</td>
<td>Some info</td>
<td>Some info</td>
</tr>
</tbody>
<thead>
<tr>
<td>Some info</td>
<td>Some info</td>
<td>Some info</td>
</tr>
</thead>
<tbody>
<tr>
<td>Some info</td>
<td>Some info</td>
<td>Some info</td>
</tr>
</tbody>
</table>
一些信息
一些信息
一些信息
一些信息
一些信息
一些信息
一些信息
一些信息
一些信息
一些信息
一些信息
一些信息
一些信息
一些信息
一些信息
我想计算一下使用jQuery(或普通Javascript)的两个
thead
之间存在多少tbody
。有什么方法可以做到这一点吗?此外,标记无效,但对于您的示例,您可以使用以下内容:
$("table thead:first").nextUntil("thead").length
演示:您可以创建一个通用函数
function countHeader(pos1, pos2) {
return $('table thead:eq('+ pos1 +')').nextUntil('thead:eq('+ pos2 +')').length;
}
使用:
注
您的标记是错误的,请避免它。尝试使用简化的迭代器来获取
tbody
之间的所有thead
var tbodyM = [];
$('table thead').each (function (idx) {
tbodyM.push($(this).nextUntil('thead').length);
});
演示:@Xeon06这不是我的代码。那个HTML来自另一个页面,我正在用jQuery解析它。@NathanCampos耸耸肩,只是说“但是如果我想得到从第二个
到第三个
?@NathanCampos使用:eq(1)
选择器(依此类推),而不是:first
。
var tbodyM = [];
$('table thead').each (function (idx) {
tbodyM.push($(this).nextUntil('thead').length);
});