このjQueryスニペットをtr
を処理するように記述しました。ブートストラップクラスを追加して最初のcheckbox
をクリックします。私はtr
をクリックするので、この呼び出しトリガーたび手動でトリガした後にチェックボックスが機能しなくなる
$('body').on('change', '.select-all-children', function(e) {
var checked = this.checked;
$('.select-child').each(function() {
$(this).prop('checked', checked);
if(checked) {
$(this).parent().parent().addClass('warning');
} else {
$(this).parent().parent().removeClass('warning');
}
});
});
$('body').on('click', '.table-selectable tbody tr', function(e) {
var checkbox = $(this).find('.select-child');
checkbox.click();
var checked = checkbox[0].checked;
if(checked) {
$(this).addClass('warning');
} else {
$(this).removeClass('warning');
}
});
$('body').on('change', '.select-child', function(e) {
var checked_total = $('.select-child:checked').length;
if(checked_total == $('.select-child').length) {
$('.select-all-children').prop('checked', true);
} else {
$('.select-all-children').prop('checked', false);
}
});
:
checkbox.click();
を私はこれ以上のチェックボックスをクリックすることはできませんが、tr
クリックが正常に動作します。
これは、テーブルの私のHTMLマークアップです:
<table class="table table-selectable">
<thead>
<tr>
<th>
<input type="checkbox" class="select-all-children">
</th>
</tr>
</thead>
<tbody>
<tr>
<tr>
<td>
<input type="checkbox" class="select-child">
</td>
</tr>
</tr>
</tbody>
</table>
動作しません。この場合は未定義の関数を呼び出すことはできません。 – omerowitz