jQuery选中列中的所有复选框 [英] JQuery check all checkboxes in column
本文介绍了jQuery选中列中的所有复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这张桌子:
当我单击一列中的全部检查"时,它假定该列中的所有复选框均已选中,否则. 这是我的JQuqey:
When i click 'Check all' in one column, its supposed that all check boxes in that column with be checked and otherwise. Here is my JQuqey:
$(document).ready(function() {
$('[id^="check_"]').on('click', function(){
perm_type=$(this).attr('id');
type=perm_type.substring(6);
if(!($('#check_'+type).attr('checked'))) {
$("[id^=client_type_"+type+"]").attr('checked', true);
$('#check_'+type).attr('checked', true);
}
else {
$("[id^=client_type_"+type+"]").attr('checked',false);
$('#check_'+type).attr('checked',false);
}
});
});
有我的html:
echo '<tr bgcolor="'.($bgcol[$inx % 2]).'"><td></td><td></td><td></td><td></td><td></td><td></td></tr>';
echo '<tr bgcolor="'.($bgcol[$inx % 2]).'">';
echo '<td valign="top" align="center"><b>';
echo $row['title'];
echo '</b></td>';
echo '<td valign="top" align="center">';
echo '<b>Clients Types</b>';
echo '</td>';
echo '<td valign="top" align="center">';
echo "<input type='checkbox' id='check_select'> Check all";
echo '</td>';
echo '<td valign="top" align="center">';
echo "<input type='checkbox' id='check_insert'> Check all";
echo '</td>';
echo '<td valign="top" align="center">';
echo "<input type='checkbox' id='check_update'> Check all";
echo '</td>';
echo '<td valign="top" align="center">';
echo "<input type='checkbox' id='check_delete'> Check all";
echo '</td>';
echo "</tr>";
$nr=0;
$cli = //my query here;
$result=$db->sql_query($cli);
while($r=$db->sql_fetchrow($result)){
$s =$db->sql_fetchrow($db->sql_query(//my query here"));
echo '<tr bgcolor="'.($bgcol[$inx % 2]).'">';
echo '<td></td><td valign="top" align="center">';
echo $r['type'];
echo "<input type='hidden' id='cli_type_id".$nr."' value='".$r['type_id']."'>";
echo '</td>';
echo '<td valign="top" align="center">';
echo "<input type='checkbox' name='rights[".$r['type_id']."][select]' id='client_type_select".$nr."' value='true' "; echo $s['sel']?"checked":""; echo ">";
echo '</td>';
echo '<td valign="top" align="center">';
echo "<input type='checkbox' name='rights[".$r['type_id']."][insert]' id='client_type_insert".$nr."' value='true' "; echo $s['ins']?"checked":""; echo ">";
echo '</td>';
echo '<td valign="top" align="center">';
echo "<input type='checkbox' name='rights[".$r['type_id']."][update]' id='client_type_update".$nr."' value='true' "; echo $s['upd']?"checked":""; echo ">";
echo '</td>';
echo '<td valign="top" align="center">';
echo "<input type='checkbox' name='rights[".$r['type_id']."][delete]' id='client_type_delete".$nr."' value='true' "; echo $s['del']?"checked":""; echo ">";
echo '</td>';
echo "</tr>";
$nr++;
}
当前结果是:第一次1个检查/取消选中全部检查"时,它确实起作用,但是如果我再次检查全部检查",则不是什么. 请任何人帮助我!
The current result is: When 1 check/uncheck for the first time 'check all', it does function, but if i check again 'check all', is doesn't nothing. Please anybody help me!
推荐答案
我猜:
$(function() {
$('[id^="check_"]').on('change', function(){
var type = this.id.split('_')[1];
$('[id^="client_type_'+type+'"]').prop('checked', this.checked);
});
这篇关于jQuery选中列中的所有复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文