您好我发现它使用复选框以选择所有的脚本/取消选择所有checkboxex,我发现这里http://jsfiddle.net/ThiefMaster/HuM4Q/复选框切换选择所有/取消选择所有问题
工作示例的问题是,当我试图把它集成到我自己HTML。它doenst工作了,这里是我的代码:
的javascript:
<head>
<script>
$('#checkAll').click(function() {
if(this.checked) {
$('input:checkbox').attr('checked', true);
}
else {
$('input:checkbox').removeAttr('checked');
}
});
$('input:checkbox:not(#checkAll)').click(function() {
if(!this.checked) {
$('#checkAll').removeAttr('checked');
}
else {
var numChecked = $('input:checkbox:checked:not(#checkAll)').length;
var numTotal = $('input:checkbox:not(#checkAll)').length;
if(numTotal == numChecked) {
$('#checkAll').attr('checked', true);
}
}
});
</script>
</head>
而这些是我的html:
<h2>Courses</h2>
<?php
$attributes = array('name' => 'list','id' => 'form');
echo form_open('courses/edit',$attributes);?>
<table class="data display datatable" id="example">
<thead>
<tr>
<th>ID</th>
<th>Title</th>
<th>Description</th>
<th>Units</th>
<th>Notes</th>
<th><input type="checkbox" id="checkAll"></th>
</tr>
</thead>
<tbody>
<?php foreach($query->result_array() as $row): ?>
<tr class="even gradeC">
<td><?php echo anchor('courses/details/'.$row['courseID'],$row['courseID']);?></td>
<td><?php echo $row['courseTitle'];?></td>
<td><?php echo $row['courseDesc'];?></td>
<td><?php echo $row['courseUnits'];?></td>
<td><?php echo $row['courseNotes'];?></td>
<td><input type="checkbox" name="checkID[]" id="checkID" value="<?php echo $row['courseID'];?>"/></td>
</tr>
<? endforeach; ?>
</tbody>
</table>
我已经包括jQuery中的标题..但仍然不工作 – 2011-06-07 04:33:59
我使用checkID [],因为我的数据来自数据库..多数民众赞成为什么我只是循环它..有没有办法如何工作呢? – 2011-06-07 04:34:58
name =属性很好,我指的是id =属性 - 这应该是唯一的。取出id =“checkID”。 – baraboom 2011-06-07 05:36:18