考虑下表:
<table>
<thead>
<tr>
<th scope="col" />
<th scope="col">A</th>
<th scope="col">B</th>
<th scope="col">C</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>Apples</td>
<td>Oranges</td>
<td>Pears</td>
</tr>
<tr>
<th scope="row">2</th>
<td rowspan="2">Subcategory Heading</td>
<td>ASP.Net</td>
<td>Other</td>
</tr>
<tr>
<th scope="row">3</th>
<td>MVC</td>
<td>PHP</td>
</tr>
<tr>
<th scope="row">4</th>
<td>Red</td>
<td>Green</td>
<td>Blue</td>
</tr>
</tbody>
<tfoot>
<tr>
<td colspan="4">Some pointless footer content</td>
</tr>
</tfoot>
</table>
如何使用 jQuery 检索包含文本“MVC”或“PHP”的单元格的正确列号?正确答案是第 3 列,但只需使用.prevAll().length
只会计算先前单元格的数量,在这种情况下这不能准确反映它们的实际列位置?
我确定我需要使用each()
,但我也在寻找最有效的实现。
我最近针对同样的问题写了一个针对这种情况的解决方案:
如何使用 jQuery 找到每个表格单元格的“视觉位置”? https://stackoverflow.com/questions/10966687/how-can-i-find-each-table-cells-visual-location-using-jquery/10967488#10967488
对于寻找这个的人来说可能是另一个解决方案。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)