Javascript 单击复选框后显示/隐藏表行

Javascript 单击复选框后显示/隐藏表行,javascript,jquery,Javascript,Jquery,我希望在用户单击复选框后删除所有表行,但带有复选框的表行除外,并在再次取消选中复选框时显示表行。我的代码仅用于删除,但取消选中后需要再次显示该表 function Showhidefunc(btndel) { if (typeof(btndel) == "object") { $('table tr td:first-child :checkbox:not(:checked)').closest('tr').remove(); } else { return fals

我希望在用户单击复选框后删除所有表行,但带有复选框的表行除外,并在再次取消选中复选框时显示表行。我的代码仅用于删除,但取消选中后需要再次显示该表

function Showhidefunc(btndel) {
  if (typeof(btndel) == "object") {
    $('table tr td:first-child :checkbox:not(:checked)').closest('tr').remove();
  } else {
      return false;
  }
}

<thead>
<tr>
   <th>Select</th>
   <th>Month</th>
   <th>Username</th>
   <th>Deduction</th>
</tr>
</thead>
<tbody>
<tr>
  <td><input type="checkbox" onChange="Showhidefunc(this);"></td>
  <td><?php echo $Name_row ['Month'];?></td>
  <td><?php echo $Name_row ['Username'];?></td>
  <td><?php echo $Name_row ['Total_Deduction'];?></td>
</tr>
</tbody>
函数Showhidefunc(btndel){
if(类型化(btndel)=“对象”){
$('table tr td:first child:checkbox:not(:checked')。最近('tr')。remove();
}否则{
返回false;
}
}
挑选
月
用户名
演绎

谢谢大家:)

函数Showhidefunc(btndel){ if(类型化(btndel)=“对象”){ $('table tr td:first child:checkbox:not(:checked')。最近('tr')。remove(); }否则 { 返回false; } }

.remove应该是
.hide()


在else中,您希望执行相同的操作,但使用
.show()
函数Showhidefunc(btndel){ if(类型化(btndel)=“对象”){ $('table tr td:first child:checkbox:not(:checked')。最近('tr')。remove(); }否则 { 返回false; } }

.remove应该是
.hide()

在else中,您希望执行相同的操作,但使用
.show()
代替不要在行上使用
.remove()
,因为这样会删除行;一旦你把它们拿走,它们就不见了,你再也拿不回来了

使用
.hide()
然后使用
.show()

更新:更新代码以匹配html和更好的if/else

版本包括:

另外,还有其他方法可以做到这一点,例如使用
.map()

不要在行上使用
.remove()
,因为这样会删除它们;一旦你把它们拿走,它们就不见了,你再也拿不回来了

使用
.hide()
然后使用
.show()

更新:更新代码以匹配html和更好的if/else

版本包括:


另一方面,还有其他方法可以做到这一点,例如使用
.map()

不要
.remove()
行-一旦删除它们,它们就消失了。使用
.hide()
然后使用
.show()
你可以使用jQuery。这对我也有帮助,谢谢。不要
.remove()
行-一旦删除它们,它们就消失了。使用
.hide()
然后使用
.show()
你可以使用jQuery。这对我也有帮助,谢谢。
function Showhidefunc(chkbox) {
    if ($(chkbox).is(":checked"))
        $('table tr td:first-child :checkbox:not(:checked)').closest('tr').hide();
    } else {
        $('table tr td:first-child :checkbox:not(:checked)').closest('tr').show();
    }
  }
function Showhidefunc(chkbox) {
    $('table tr td:first-child :checkbox:not(:checked)').closest('tr').toggle(!$(chkbox).is(":checked"));
  }