我有一个带有复选框的表格,我想执行“选中所有”和“取消选中所有”复选框,但我找不到选中所有复选框的方法。
这是我的代码:
<form>
<?php foreach ($this->entries as $entry): ?>
<tr class="table_head_seperator">
<td class="grid_info" width="32px" bgcolor="#f6f6f6"><input type="checkbox" class="chk_boxes1" name="to_delete[<?PHP echo $entry['id'] ?>]" /></td>
<td class="grid_info" width="160px" bgcolor="#eeeeee"><span class="country_name"><?php echo $entry['user_name'] ?></span></td>
<td class="grid_info" width="130px" bgcolor="#eeeeee"><span class="country_name"><?php echo $entry['date_created'] ?></span></td>
<td class="grid_info" width="100px" bgcolor="#f6f6f6"><span class="country_name"><?php echo $entry['user_type_name'] ?></span></td>
</tr>
<?PHP endforeach; ?>
<input type="checkbox" class="chk_boxes" label="check all" />check all
<input type="checkbox" class="unchk_boxes" /> un-check all
</form>
<script type="text/javascript">
$(document).ready(function() {
$('.chk_boxes').click(function(){
$('.chk_boxes1').attr('checked',checked)
})
});
</script>
最佳答案
$(function() {
$('.chk_boxes').click(function() {
$('.chk_boxes1').prop('checked', this.checked);
});
});
这只会影响 check all
框。 但是您为什么要使用两个复选框呢?一个选中所有,一个取消选中所有,但不是相互排斥的。这一定是混淆用户的秘诀:)
关于php - 选中所有复选框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6689861/