Jquery pdo表的复选框过滤器

Jquery pdo表的复选框过滤器,jquery,checkbox,pdo,filter,Jquery,Checkbox,Pdo,Filter,我试图创建一个复选框过滤器,它隐藏表中所有未选中的行。这是一个业务联系人表,每个联系人都有一个优先级复选框,如果选中该复选框,并且您点击过滤器,则会隐藏所有非prio联系人 以下是我目前的代码: 过滤器按钮: <ul id="filters"> <li> <input type="checkbox" class="inputprio" id="filter-prio" /> <label for="filter-prio">Sofo

我试图创建一个复选框过滤器,它隐藏表中所有未选中的行。这是一个业务联系人表,每个联系人都有一个优先级复选框,如果选中该复选框,并且您点击过滤器,则会隐藏所有非prio联系人

以下是我目前的代码:

过滤器按钮:

<ul id="filters">
<li>
    <input type="checkbox" class="inputprio" id="filter-prio" />
    <label for="filter-prio">Sofortkontakt</label>
</li>
<li>
    <input type="checkbox" class="inputnorm" id="filter-norm" />
    <label for="filter-norm">Normalkontakt</label>
</li>
  • 索福特康塔克
  • 诺曼康塔克

下表:

<?php while($dsk=$stmk->fetch(PDO::FETCH_ASSOC)) : ?>

   <tr>
       <form method="post" action="kontakte.php">
     <td class="box">
        <input name="prio" class="outprio" type="checkbox" <?= $dsk['Sofortkunde'] ? "checked": ""; ?>>
     </td>
    <td class="box" style="font-size:14px;">
       <p class="label-input"><?= htmlspecialchars($dsk['Termin']); ?></p>
       <input name="termin" class="edit-input" type="date" value="<?= htmlspecialchars($dsk['Termin']); ?>" style="display:none" required>
     </td>
     <td class="box" style="font-size:14px;">
       <p class="label-input"><?= htmlspecialchars($dsk['Name']); ?></p>
       <input name="name" class="edit-input" value="<?= htmlspecialchars($dsk['Name']); ?>" style="display:none; padding: 0;" required>
     </td>
     <td class="box" style="font-size:14px;">
       <p class="label-input"><?= htmlspecialchars($dsk['Vorname']); ?></p>
       <input name="vorname" class="edit-input" value="<?= htmlspecialchars($dsk['Vorname']); ?>" style="display:none; padding: 0;" required>
     </td>
     <td class="box" style="font-size:14px;">
       <p class="label-input"><?= htmlspecialchars($dsk['Geburtsdatum']); ?></p>
       <input name="geburtsdatum" class="edit-input" type="date" value="<?= htmlspecialchars($dsk['Geburtsdatum']); ?>" style="display:none; padding: 0;" required>
     </td>
     <td class="box" style="font-size:14px;">
       <p class="label-input"><?= htmlspecialchars($dsk['Beruf']); ?></p>
       <input name="beruf" class="edit-input" value="<?= htmlspecialchars($dsk['Beruf']); ?>" style="display:none; padding: 0;" required>
     </td>
     <td class="box" style="font-size:14px;">
       <p class="label-input"><?= htmlspecialchars($dsk['Telefon']); ?></p>
       <input name="telefon" class="edit-input" type="tel" value="<?= htmlspecialchars($dsk['Telefon']); ?>" style="display:none; padding: 0;" required>
     </td>
     <td class="box" style="font-size:14px;">
       <p class="label-input"><?= htmlspecialchars($dsk['Info']); ?></p>
       <input name="info" class="edit-input" value="<?= htmlspecialchars($dsk['Info']); ?>" style="display:none; padding: 0;" required>
     </td>
     <td class="box" style="font-size:14px;">
        <p class="label-input"><?= htmlspecialchars($dsk['Anrufe']); ?></p>
        <input name="anrufe" class="edit-input" type="number" value="<?= htmlspecialchars($dsk['Anrufe']); ?>" style="display:none; padding: 0;" required>
     </td>
     <td class="box" style="font-size:14px;">
         <p class="label-input"><?= htmlspecialchars($dsk['Art']); ?></p>
         <input name="art" class="edit-input" value="<?= htmlspecialchars($dsk['Art']); ?>" style="display:none; padding: 0;" required>
     </td>
     <td>
         <button  class="btn btn-danger" name="update" value="speichern" style="padding: 0;" type="submit">Speichern</button>
     </td>
         <input name="hidden" value="<?= htmlspecialchars($dsk['ID']); ?>" type="hidden">

</form>


我自己找到了答案,因此对于每个有相同问题的人,我的解决方案如下:

$(function(){
$(document).on('change', '.inputprio', function(){


  if($('.inputprio').prop('checked')) {  

    $('.outprio:not(:checked)').parent().parent().hide();  

  }
  else {
    $('.outprio').parent().parent().show(); 
  }

});
});
您不需要寻址,而是告诉所有未经检查的outprio输入隐藏第二个父项,这使事情变得更容易

$(function(){
$(document).on('change', '.inputprio', function(){


  if($('.inputprio').prop('checked')) {  

    $('.outprio:not(:checked)').parent().parent().hide();  

  }
  else {
    $('.outprio').parent().parent().show(); 
  }

});
});