我正在使用表格中的複選框,並且在tablehead中有一個複選框。使用jQuery選擇表格中的所有複選框
我所試圖實現當我點擊在頭上的複選框,所有在下面的錶行的複選框應檢查..
這裏是我的HTML:
<form action="<?php $_PHP_SELF ?>" method="post">
<div class="content top">
<table id="datatable_example" class="responsive table table-striped table-bordered" style="width:100%;margin-bottom:0; ">
<thead>
<tr>
<th style="width:0px; padding-right:0px;" class="no_sort"> <label class="checkbox ">
<input type="checkbox" id="checkAll" name="checkAll" class="select_all">
</label>
</th>
<th style="width:200px;" class="no_sort"> Institue </th>
<th style="width:150px;" class="no_sort"> Education </th>
<th style="width:300px;" class="no_sort"> Description </th>
<th style="width:150px;" class="ue no_sort"> Started </th>
<th style="width:150px;" class="ue no_sort"> Completion </th>
<th class="ms no_sort "> Actions </th>
</tr>
</thead>
<tbody>
<?php echo $educations ?>
</tbody>
</table>
<div class="row-fluid control-group">
<div class="pull-left span6 " action="#">
<div>
<div class="controls inline input-large pull-left">
<select name="bulkaction" data-placeholder="Bulk actions: " class="chzn-select " id="default-select">
<option value=""></option>
<option value="delete">Delete</option>
</select>
</div>
<button type="submit" name="submitbulkaction" class="btn btn-inverse inline">Apply</button></form>
這裏是php這是在表中使用變量$教育..
$educations .= "<tr>
<td><label class=\"checkbox\">
<input type=\"checkbox\" class=\"chkboxes\" name=\"ids[]\" value=\"$education_id\">
</label></td>
<td class=\"to_hide_phone\"> $institue_name</td>
<td class=\"to_hide_phone\"> $education_name</td>
<td>$education_desc</td>
<td>$education_started</td>
<td>$education_ended</td>
<td class=\"ms\">
<div class=\"btn-group1\">
<a href=\"education-edit.php?id=$education_id\" class=\"btn btn-small\" rel=\"tooltip\" data-placement=\"left\" data-original-title=\" edit \">
<i class=\"gicon-edit\"></i></a>
<a class=\"btn btn-small\" rel=\"tooltip\" data-placement=\"top\" data-original-title=\"View\">
<i class=\"gicon-eye-open\"></i>
</a>
<a class=\"btn btn-small\" rel=\"tooltip\" data-placement=\"bottom\" data-original-title=\"Remove\"><i class=\"gicon-remove \"></i></a>
</div>
</td>
</tr>";
jQuery的背後我想設置..
<script type="text/javascript">
$(document).ready(function(){
$('#checkAll').click(function() {
$('.chkboxes').attr('checked','checked');
});
});
</script>
請告訴我什麼是我在這裏做錯了,以及如何解決這個問題?
我看過其他問題,也發佈了關於同一問題複選框,他們中的大多數都解決了,但仍然仍然當我應用相同的代碼,我沒有得到我想要的結果。
更新:我固定爲大家提到的類名錯誤,謝謝你, 但現在它的一些奇怪的問題出現了。 我的意思是現在它的工作,但它不工作,就像我點擊複選框,所有複選框得到選擇在旅途中..我不得不刷新頁面,然後所有複選框將被選中? 這個問題是怎麼回事? 爲什麼我需要刷新該事件發生的頁面?
StackOverflow不是這個問題的適當位置。我們不做代碼調試。您需要進行自己的調試,如果您不確定爲什麼某些功能不能按預期工作,請在代碼中加上解釋您期望執行的操作的內容,以及實際執行的操作,包括所有錯誤消息。看[ask advice](http://stackoverflow.com/questions/ask-advice)。 –
從我看到你正在嘗試使用'.checkboxes'並在你的PHP代碼中使用'.chkboxes' –
@MarcusRecck Thankyou,我更新了我的錯誤,但現在出現了新問題。 當我點擊複選框選擇所有它沒有被選擇在那一刻,但當我點擊重新加載按鈕,然後所有複選框被選中因爲我刷新頁面之前點擊複選框的因素。 –