【发布时间】:2020-03-23 21:18:38
【问题描述】:
我使用datatable进行数据收集,我使用datatable中的checkbox功能以删除和编辑按钮的形式选择需要执行的数据,我的删除和编辑按钮会在checkbox的时候一起出现在 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