如何选择所有行的HTML表 [英] How to select all rows HTML table
本文介绍了如何选择所有行的HTML表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到了一个我自己无法解决的问题!
I came across a problem which I can't solve on my own!
我有一个使用PHP/MySQL填充的表
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
我需要做的是使用mainCheckbox选中/取消选中所有复选框,是否有一种方法可以仅通过选中该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?
当您选择输入之类的东西时如何找到班级,有没有办法为此找到班级?例如
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?
推荐答案
此:
$('#all').on('click', function(){
$(':checkbox').prop("checked",$(this).is(':checked'));
});
这篇关于如何选择所有行的HTML表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文