我想知道如何使用 jquery 过滤方法做这些事情:
选择表格行中的单元格 1 至 4 和 6 至 8。
或
选择该表 TR 中的单元格 1 以及单元格 6 到 8。
我已经测试了这些方法,但它们没有用。
对于第一个:filter('gt(2):lt(4),gt(7):lt(8))'
对于第二个:filter('eq(2),gt(7):lt(8)')
在下面的代码中,结果可能类似于(第一个单元格编号为 1 到 8,不包括第一个单元格 5)和(第二个单元格为单元格 1 单元格 6 单元格 7 单元格 8
<table cellpadding="0" cellspacing="0" border="0" class="display" id="selection">
<tbody>
<tr>
<td>cell1</td>
<td>cell2</td>
<td>cell3</td>
<td>cell4</td>
<td>cell4</td>
<td>cell5</td>
<td>cell6</td>
<td>cell7</td>
<td>cell8</td>
</tr>
</tbody>
</table>
谢谢。
最佳答案
您可以使用 jquery 过滤器。
// exclude 5th column (zero based indexes)
$(your_selector_to_cels).filter(function(index) { return index != 4; })
// get only column 1, 6, 7, 8
$(your_selector_to_cels).filter(function(index) { return index == 0 || (index >= 5 && index <= 7); })
我不知道你想用多硬的编码来做到这一点,但这是一种方法。
关于Jquery 使用过滤器方法中的表达式在表行中多个选择单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12040612/