【发布时间】:2014-10-01 01:48:13
【问题描述】:
当复选框被选中时,我试图通过 tr 删除。如果我知道给定行的 id 但我的表是由 PHP foreach 循环生成的,我可以这样做。以下代码有效,但所有行在每个 td 中都有一条线。我只想要选中复选框的行。
<script>
$('input.complete').on('click', function(e) {
if (this.checked) {
$("td").addClass('newclass');
} else {
$("td").removeClass('newclass');
}
});
</script>
该表由以下 PHP foreach 循环生成:
<?php foreach ($tasks as $task):?>
<tr>
<td><?php echo $task->id;?></td>
<td rowid="<?php echo $task->id;?>"><?php echo $task->task_name;?></td>
<td><?php echo $task->task_desc;?></td>
<td><input class="complete" type="checkbox" name="complete" value="CheckBox"></td>
</tr>
<?php endforeach;?>
css 很简单:
.newclass {
text-decoration: line-through;
}
我尝试使用父选择器和子选择器隔离行,但似乎无法解决。如何只获得选中的行?
【问题讨论】: