简体   繁体   中英

How to select all rows HTML table

I came across a problem which I can't solve on my own!

I have a Table which is populated using PHP/MySQL something like

foreach($users as $user){
    ?> <tr id="<?php echo $user['fName'].
            "-".$user['lName'];?>">
        <td> <?php 
            echo $user['fName']." ".$user['lName']; 
        ?> </td>
       <?php 
            for ($i = 0; $i<$count+3; $i++){
                ?> <td><input class="accessCheck" id="<?php
                echo $user['lName']."-".$pagesArray[$i];
                ?>" type="checkbox"></td> 
      <?php } ?>
   </tr> <?php 
}

As you can see table would look something like

fName lName | checkbox | checkbox | checkbox | mainCheckbox 

What I need to do is to check/uncheck all checkboxes with mainCheckbox, is there a way to select all rows just from checking this mainCheckbox?

EDIT: How to find class when you select something like input, is there a way of finding a class for this? For example

$("input").click(function(){

});

Is there a way to find a class for this input?

Tyr this:

$('#all').on('click', function(){
    $(':checkbox').prop("checked",$(this).is(':checked'));
});

http://jsfiddle.net/Dfzdh/

I think you would need to use jQuery Look at the sibblings method. Here is a question close to yours. OnClick change all sibling table rows jQuery

I havent heard about any "onChange"-equivalent function in PHP yet

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM