您好我發現它使用複選框以選擇所有的腳本/取消選擇所有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