複数のチェックボックスに基づいて行を表示/非表示にするHTMLテーブルがあります。複数のチェックボックスを含む行を非表示
(テキスト基準に基づいて)チェックボックスをオンにすると、一部の行が非表示になります。チェックが外されていると、すべての行が表示されます。 2つ以上のチェックボックスがチェックされている場合、すべての選択されたチェックボックスの基準を満たした行を除いて、すべての行が隠れています。しかし、チェクボックスのチェックを外すと、すべての行が表示されます。
私がチェックボックスをオフにすると、現在選択されているすべてのチェックボックスの基準を満たしている行のみを表示するにはどうすればよいですか?
わかりやすくするために、チェックボックスをオフにしたときに、他のチェックボックスで既に非表示になっている行を確認し、表示しないようにする必要があります。作業例
例: CheckBox1をとcheckbox2が選択されています:だけROW1が示されている、私はcheckbox2のチェックを外した場合のみ、ROW1とROW3が示されなければならない
HTML:
<label><input type="checkbox" id="checkbox1">Teacher</label>
<label><input type="checkbox" id="checkbox2">Tennis</label>
<label><input type="checkbox" id="checkbox3">Married</label>
<table id="table" border="1">
<thead>
<th>First Name</th>
<th>Last Name</th>
<th>Profession</th>
<th>Hobby</th>
<th>Married</th>
</thead>
<tbody>
<tr id="row1">
<td>John</td>
<td>Doe</td>
<td>Teacher</td>
<td>Tennis</td>
<td>Yes</td>
</tr>
<tr id="row2">
<td>Eve</td>
<td>Jackson</td>
<td>Doctor</td>
<td>Darts</td>
<td>No</td>
</tr>
<tr id="row3">
<td>Adam</td>
<td>Johnson</td>
<td>Teacher</td>
<td>Skydiving</td>
<td>Yes</td>
</tr>
<tr id="row4">
<td>Nina</td>
<td>Pursuit</td>
<td>Lawyer</td>
<td>Tennis</td>
<td>Yes</td>
</tr>
</tbody>
</table>
のjQuery:
$(document).ready(function() {
$('#checkbox1').change(function() {
for (var i = 0; i < 5; i++) {
if ((this.checked) && $("#table #row"+i+" td:nth-child(3):not(:contains('Teacher'))").length){
$('#row'+i).fadeOut('slow');
}
if (!this.checked) $('#row'+i).fadeIn('slow');
}
});
$('#checkbox2').change(function() {
for (var i = 0; i < 5; i++) {
if ((this.checked) && $("#table #row"+i+" td:nth-child(4):not(:contains('Tennis'))").length){
$('#row'+i).fadeOut('slow');
}
if (!this.checked) $('#row'+i).fadeIn('slow');
}
});
$('#checkbox3').change(function() {
for (var i = 0; i < 5; i++) {
if ((this.checked) && $("#table #row"+i+" td:nth-child(5):not(:contains('Yes'))").length){
$('#row'+i).fadeOut('slow');
}
if (!this.checked) $('#row'+i).fadeIn('slow');
}
});
});