<table>
<thead>
<tr>
<th>
<input type="checkbox" name="a">
</th>
</tr>
</thead>
<tbody>
<?php foreach($data as $val):?>
<tr><td><input type="checkbox" name="b[]">
<?php endforeach;?>
</tbody>
<script src="/js/jquery.min.js"></script>
<script type="text/javascript">
//方法1:----------------------------------------------
$(function(){
$("input[name=a]").click(function(){
$(":checkbox").prop("checked",this.checked);
})
})
//方法2-----------------------------------
$("input[name=a]").click(function(){
if(this.checked){
$("tbody input[type=checkbox]").each(function(){
this.checked=true;
});
}else{
$("tbody input[type=checkbox]").each(function(){
this.checked=false;
});
}
})
</script>