Html 选择/取消选择所有不在动态表行中工作的复选框

Html 选择/取消选择所有不在动态表行中工作的复选框,html,codeigniter,Html,Codeigniter,对于下面的代码,我只是尝试选择/取消选择表行中的所有复选框,通常jquery代码在静态表中工作正常,但在动态表中不工作,在动态表中,行使用foreach生成。我真的没有发现我错过了什么,因为我是新来的 jquery: $('#chkall').click(function(event) { //on click if(this.checked) { // check select status $('.TID').ea

对于下面的代码,我只是尝试选择/取消选择表行中的所有复选框,通常jquery代码在静态表中工作正常,但在动态表中不工作,在动态表中,行使用
foreach
生成。我真的没有发现我错过了什么,因为我是新来的

jquery:

 $('#chkall').click(function(event) {  //on click 
                if(this.checked) { // check select status
                    $('.TID').each(function() { //loop through each checkbox
                        this.checked = true;  //select all checkboxes with class "checkbox1"               
                    });
                }else{
                    $('.TID').each(function() { //loop through each checkbox
                        this.checked = false; //deselect all checkboxes with class "checkbox1"                       
                    });         
                }
            });
查看页面:

<form role="form" action="<?php echo base_url(); ?>attendance/statusUpdate/" method="post" name="attendance" id="attendance">
            <table class='table table-condensed table-bordered table-hover text-center' cellspacing='0' cellpadding='0' width='100%' id='tabledata'>
                <thead>
                    <tr class='info'>
                        <th class="text-center">Sl#</th>
                        <th class="text-center">Trainee ID</th>
                        <th class="text-center">Trainee Name</th>
                        <th class="text-center">Date</th>
                        <th class="text-center">In Time</th>
                        <th class="text-center">Out Time</th>
                        <th class="text-center">Status</th>
                        <th class="text-center">Withdraw</th>
                        <?php
                        if (isset($userinfo) and ( $userinfo->Role == 1)) {
                        ?> 
                        <th class="text-center">Allow <input type='checkbox' name='chkall' id='chkall'></th>
                        <th class="text-center">Remarks</th>
                        <?php
                        }
                        ?>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td colspan="10">Session # </td>
                    </tr>
                    <tr>
                        <td>Faculty:</td>
                        <td colspan="2"> </td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <?php
                        if (isset($userinfo) and ( $userinfo->Role == 1)) {
                        ?> 
                        <td></td>
                        <td></td>
                        <?php
                        }
                        ?>
                    </tr>
                <?php
                $i = 0;
                foreach($attendance as $row){
                    $i++;
                    if ($row->Status=='Late-In' or $row->attnDate == null) {
                        $style='red';
                    }else{
                        $style='black';
                    }
                ?>  
                    <tr style="color:<?php echo $style?>"><td><?=$i?></td>
                        <td><?=str_pad($row->TraineeID, 7, "0", STR_PAD_LEFT)?></td>
                        <td class="text-left"><?=$row->Name?></td>
                        <td><?=$row->attnDate?></td>
                        <td><?=$row->inTime?></td>
                        <td><?=$row->outTime?></td>
                        <td><?=$row->Status?></td>
                        <td><?=$row->Reason?></td>
                        <?php
                        if (isset($userinfo) and ( $userinfo->Role == 1)) {
                        ?> 
                        <td>
                            <input type='checkbox' name='TraineeID[]' class="TID" id="TID" value="<?=$row->TraineeID ?>"
                            <?php if($row->Status==='Late-In')
                                {
                            ?>   
                                unchecked>
                            <?php
                                }else if($row->Status==='Present'){
                            ?>
                               checked>
                            <?php
                                }
                            ?>
                        </td>
                        <td>
                            <input type="text" name="remarks[]" id="remarks">
                        </td>
                        <?php
                        }
                        ?>
                <?php
                }
                ?> 
                    </tr>
                </tbody>
    <?php        
    }
    ?>
            </table>
        </form>

容许
评论
会议#
教员:
未选中>
选中>
我认为您需要将事件绑定到页面中的静态对象,例如:
#tabledata
Try
$(“input.TID”).prop('checked',true)
$(“input.TID”).prop('checked',false)

除去

$('#tabledata .TID').each(function() {});

美元的出勤价值是多少?复选框是否正确显示?
$attention
是数组,并正确显示复选框。您不能为多个输入框分配相同的id
TID
。是的,先生,我为所有输入框分配了相同的id。您可以在查看页面代码上查看一下。先生,您能提到它的不同之处吗?
$('#chkall')。单击(函数(事件){if(this.checked){$('input.TID').prop('checked',true);}否则{$('input.TID').prop('checked',false);                              }                 });尝试过这个,但没有运气。
$('#tabledata .TID').each(function() {});