鑑於上面的圖片,如果用戶取消選中複選框#2,我試圖讓它取消選中複選框#1爲好。目前,當我取消選中複選框#2時,我的代碼將取消選中#1和#3。
HTML代碼(消毒和簡化的)
<!--Grouping Row 1-->
<tr id="group-id-example_insertjobname">
<td colspan="11" data-group="-b-insertjobname" data-group-level="0">
<input type="checkbox" class="check" name="" value="">
</td>
</tr>
<!--Grouping Row 1-->
<tr role="row" class="odd group-item" data-group="-b-XXX">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="pay">
<input type="checkbox" name="PI0" class="Invoice Open" value="">
</td>
</tr>
<tr role="row" class="group-item" data-group="-b-XXX">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="pay">
<input type="checkbox" name="PI1" class="Invoice Open" value="">
</td>
</tr>
<!--Grouping Row 2-->
<tr id="group-id-example_insertjobname">
<td colspan="11" data-group="-b-insertjobname" data-group-level="0">
<input type="checkbox" class="check" name="" value="">
</td>
</tr>
<!--Grouping Row 2-->
<tr role="row" class="odd group-item" data-group="-b-XXX">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="pay">
<input type="checkbox" name="PI3" class="Invoice Open" value="">
</td>
</tr>
<tr role="row" class="group-item" data-group="-b-XXX">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td class="pay">
<input type="checkbox" name="PI4" class="Invoice Open" value="">
</td>
</tr>
jQuery函數
$(function() {
$('.pay input[type="checkbox"]').on('change', function() {
if ($('this:checkbox:not(:checked)')) {
$('.check').prop('checked', false);
}
});
});
謝謝,Sbonkosky,我明白你想要做什麼,但是我仍然沒有找到最近的(或其他).check複選框來取消選中「子」複選框未選中時的選擇。 – dentalhero 2014-12-04 17:50:07
@dentalhero我編輯了我認爲應該可以工作的答案。我忽略了'.check'元素在'tr td'裏面。 – sbonkosky 2014-12-04 18:04:54
謝謝!這現在起作用了,我接受了你的答案。非常感激! – dentalhero 2014-12-04 18:08:16