[如何计算复选框已在DataTable中选中显示和隐藏按钮

问题描述 投票:0回答:1

我使用数据表进行数据收集,我使用数据表中的复选框功能以删除和编辑按钮的形式选择需要执行的数据,当复选框为在1个数据中选中,对于选中的复选框,如果选中多个按钮,则将其删除即可。我有一个问题,就是在我的代码之后,按钮不希望出现]

表格和按钮代码:

<div class="col s12 m12 l12">
  <button id="hapus" class="waves-effect waves-light btn" style="display: none">Hapus</button>
  <button id="status" class="waves-effect waves-light btn" style="display: none">Ubah Status</button>

 <table id="example" style="width:100%">
    <thead>
      <tr>
        <th>No</th>
        <th>Judul</th>
        <th>Tag</th>
        <th>Status</th>
        <th>Tanggal</th>
        <th></th>
        </tr>
    </thead>
 </table>

Jquery:

$(document).ready(function(){
        var xx = document.getElementById("status");
        var xy = document.getElementById("hapus");

        var $checkboxes = $('#example td input[type="checkbox"]');

        $checkboxes.change(function(){
            var countCheckedCheckboxes = $checkboxes.filter(':checked').length;

            if (countCheckedCheckboxes == 1){
                xx.style.display = "block";
                xy.style.display = "block";
            } else if (countCheckedCheckboxes >= 2) {
                xx.style.display = "none";
                xy.style.display = "block";
            } else {
                xx.style.display = "none";
                xy.style.display = "none";
            }
        }); 
    });

我使用数据表进行数据收集,我使用数据表中的复选框功能以删除和编辑按钮的形式选择需要执行的数据,我的删除和编辑计划...

javascript jquery datatable datatables
1个回答
0
投票
我认为您需要在更改方法中再次获取并计数复选框。您不能重复使用变量$ checkboxes
© www.soinside.com 2019 - 2024. All rights reserved.