<script>
$(function(){
$('.parent').on('click',function(){
$(this).find('.child[]').attr('checked',this.checked);
});
});
</script>
<table>
<thead>
<tr>
<th>S No.</th>
<th><input type="checkbox" name="select1" id="select1" class="parent" /></th>
<th>Title</th>
<th>End Date</th>
<th>Action</th>
<th>Deal Type</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<?php $sql="select * from table_name where id='$id'";
$result=mysql_query($sql);
$sn=1;
while($show=mysql_fetch_array($result))
{
$student=$show['student'];
?>
<td><?php echo $sn; ?></td>
<td><?php echo "<input type='checkbox' name='check[]' class='child[]' id='check[]' value='".$student."'/>"; ?></td>
<td>enddate</td>
<td>View</td>
<td>Edit</td>
<td>Delete</td>
<td>xyz</td>
</tr>
<?php $sn++ }}?>
這裏,checkbox-name=select1
超出循環,它是父級複選框。 checkbox-name=check
實際上是一個checkbox數組,隨數據庫一起提供數據。如果數據庫中有10個條目,則會有10個複選框。我想,如果我檢查父複選框,那麼所有的複選框應該檢查,不管你可以說的數字,就像gmail一樣。也請告訴在哪裏放置JavaScript/jQuery。謝謝您的回答。如何選擇/取消選中父複選框時在循環中生成的所有複選框
我也將腳本標記移出了html表格。正確的格式可以幫助查找問題。我無法找到'while'循環的'}','tr'打開的標籤也出現在循環之外。 – Arjan 2013-05-04 07:31:58