Javascript 如何在datatable php中添加复选框

Javascript 如何在datatable php中添加复选框,javascript,php,jquery,html,codeigniter,Javascript,Php,Jquery,Html,Codeigniter,我有一个显示查询结果的表。顺便说一下,我正在使用codeigniter。我想在每一行中添加一个复选框。每次选中复选框时,我都会启用编辑按钮和删除按钮 我是这样做的,但仅在第一行,它启用和禁用按钮: <div style="margin-top: 10px;margin-left: 10px;margin-bottom: 10px"> <a type="button" class="btn btn-default" href="<?php e

我有一个显示查询结果的表。顺便说一下,我正在使用codeigniter。我想在每一行中添加一个复选框。每次选中复选框时,我都会启用编辑按钮和删除按钮

我是这样做的,但仅在第一行,它启用和禁用按钮:

<div style="margin-top: 10px;margin-left: 10px;margin-bottom: 10px">
                <a type="button" class="btn btn-default" href="<?php echo site_url('home/create')?>" ><span class=" fa fa-plus-circle"></span> Create </a>
                <button type="button" id="edit" class="btn btn-default" disabled><span class=" fa fa-edit "></span> Edit</button>
                <button type="button" class="btn btn-default" disabled > <span class=" fa fa-trash-o"></span> Delete</button>
            </div>


        <div class="table-responsive" style="margin-right: 10px;margin-left: 10px;margin-bottom: 10px">
        <table class="table table-bordered table-hover table-striped" id="recorddata"> 

        <thead class="header">
            <tr class="well">
                <th style="width: 1px"></th>
                <th style="font-size: 14px;" >Date</th> 
                <th style="font-size: 14px;">Name</th>
                <th style="font-size: 14px;">Status</th>


            </tr>

        </thead>
        <tbody >
            <?php if($result!=null){ 
                 foreach($result as $row){?>
                    <tr>
                    <td align="center"><input type="checkbox" id="recs" name="recs[]" value="<?php echo $row->id;?>"/></td>
                 <td style="font-size: 15px;padding-left: 20px;"><?php echo $row->datee;?></td>
                  <td style="font-size: 15px;padding-left: 20px;"><?php echo $row->name;?></td>
                  <td style="font-size: 15px;padding-left: 20px;"><?php echo $row->status;?></td> 
                </tr>
                <?php }
                }
                ?>



        </tbody>
        </table><!-- END Table--></div>

编辑
删除
日期
名称
地位

您必须class而不是使用id作为复选框。检查是否选中任何复选框并启用编辑、删除按钮

<td align="center"><input type="checkbox" class="recs" name="recs[]" value="<?php echo $row->id;?>"/></td>
在此行中添加类

<td align="center"><input type="checkbox" id="recs" name="recs[]" value="<?php echo $row->id;?>"/></td>

您的意思是这样的,
因为当单击编辑按钮时,我希望它加载另一个页面并获取复选框的值..您可以添加类并触发相同的onclick事件,并且
返回false防止单击
<td align="center"><input type="checkbox" id="recs" name="recs[]" value="<?php echo $row->id;?>"/></td>
$(document).ready(function(){
    $('.your_class').click(function(){
        // check if checkbox is checked
        var checked = false;
        $(".your_class").each(function () {
            if($(this).is(":checked"))
            {
                checked = true;
            }
        });
        if(checked)
        {
            // enable buttons here

            return;
        }
        // disable buttons here
    });
});