使用数据表我可以点击所有<td>
个。如何告诉函数从前两行中排除单元格,因为我不希望这些单元格可单击?
function () {
var api = this.api();
api.$('td').click( function () {
api.search( this.innerHTML ).draw();
});},
我的表:
<table>
<thead>
<tr>
<th>Name</th>
<th>Surname</th>
<th>etc</th>
<th>etc</th>
</tr>
</thead>
<tbody>
<?php foreach ($records as $record) : ?>
<tr>
<td><?php e($record->name); ?></td>
<td><?php e($record->surname) ?></td>
<td><?php e($record->etc) ?></td>
<td><?php e($record->cetc) ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
答案 0 :(得分:0)
您可以使用not()
方法:
api.$('td').not(":nth-child(1), :nth-child(2)").click( function () {
答案 1 :(得分:0)
您可以使用lt
selector。
$('tr:lt(2) td').click(function() {
api.search(this.innerHTML).draw();
});
这会将事件绑定到前两行的td
修改强>
如果要将事件绑定到除前两行之外的行,请像这样使用
$('tr:gt(1) td').click(function() {
api.search(this.innerHTML).draw();
});
答案 2 :(得分:0)
您可以使用jquery gt()
排除前两行,请参阅下面的代码
function () {
var api = this.api();
api.$('tr:gt(1) td').click( function () {
api.search( this.innerHTML ).draw();
});},
<强> gt() API DOC 强>