php - 选中所有复选框

标签 php javascript jquery checkbox

我有一个带有复选框的表格,我想执行“选中所有”和“取消选中所有”复选框,但我找不到选中所有复选框的方法。

这是我的代码:

<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/

相关文章:

javascript - AngularJS 中过滤器的未定义参数

javascript - 如何在javascript中将数组更改为json对象

jquery - 从 anchor 标记获取文本

php - 如何匹配 [...] 的正则表达式模式

PHPmailer 发送 HTML 代码

php - 提供奇怪 URL 的工具提示子菜单链接

用户加载图像时的 jQuery 弹出对话框

php - 安装 .mobileconfig 文件后,iPhone 不会传递 Web 应用程序请求的数据

javascript - 如果存储库中不存在文件,则终止 npm start 并显示自定义错误

javascript - Jquery NivoSlider slider 不工作 $ ('#slider' ).nivoSlider();不是函数