我的任务是在DataTables中切换JavaScript,但似乎不仅按钮而且功能都无法正常运行。
以下是我的代码
HTML
<div class="col-lg-12 col-md-12 col-sm-12 mb-30">
<table class="data-table stripe hover multiple-select-row nowrap" id="example">
<thead>
<tr>
<th class="table-plus datatable-nosort">No</th>
<th>Name</th>
<th>Phone</th>
<th>Email</th>
</tr>
</thead>
<tbody>
<tr>
<td class="table-plus">1</td>
<td>Michael</td>
<td>123456789</td>
<td>michael@gmail.com</td>
</tr>
</tbody>
</table>
</div>
</div>
JS
<script>
$(function(){
$.fn.bootstrapSwitch.defaults.onColor = 'success';
$.fn.bootstrapSwitch.defaults.offColor = 'danger';
$.fn.bootstrapSwitch.defaults.size = 'mini';
$.fn.bootstrapSwitch.defaults.state = 'false';
$.fn.bootstrapSwitch.defaults.inverse = 'true';
$(".toggle-vis").bootstrapSwitch();
var table = $('#example').DataTable();
$('.toggle-vis').on('switchChange.bootstrapSwitch', function(event, state) {
event.preventDefault();
var column = table.column($(this).attr('data-column'));
column.visible( ! column.visible() );
});
});
</script>
我正在尝试复制某人的代码,这里是JSFiddle链接,但不幸的是,切换功能没有出现。
</tbody>tbody>
还是实际上出现在你的代码中?因为那可能是问题所在。 - JkAlombrobootstrapSwitch
是什么?它在哪里定义了吗? - Scaramouche