Javascript datatable多页上的jquery.switchButton
我使用jQuery的Datatable插件和jQuery的switchButton插件,如下所示:Javascript datatable多页上的jquery.switchButton,javascript,php,jquery,jquery-ui,datatable,Javascript,Php,Jquery,Jquery Ui,Datatable,我使用jQuery的Datatable插件和jQuery的switchButton插件,如下所示: <table id="test-list" class="cell-border" cellspacing="0" width="100%"> <thead> <tr> <th>Enabled ?</th> </tr> </thead>
<table id="test-list" class="cell-border" cellspacing="0" width="100%">
<thead>
<tr>
<th>Enabled ?</th>
</tr>
</thead>
<tbody>
<?php for ($i=0; $i<100; $i++) { ?>
<tr>
<td>
<input type="checkbox" class="enable-disable" name="enable-disable" value="<?php echo $i; ?>" checked />
</td>
</tr>
<?php } ?>
</tbody>
</table>
问题是:datatable第一页上的所有复选框的格式都正确(开关按钮类型),但当我转到其他页(从第二页到结束页)时,复选框的格式都不正确(传统类型)您在document.ready上有.siwtchButton,因此它将应用于页面上已经存在的元素。当您从一个页面转到下一个页面时,会动态添加新项目,并且它们不会收到switchButton()。在页面更改时找到一个处理程序并再次调用switchButton()。对,伙计。我添加了“createdRow”处理程序:“createdRow”:函数(行、数据、索引){$('.enable-disable').switchButton();}现在可以工作了。
$(document).ready(function () {
// format datatable
$('#test-list').dataTable({
"scrollCollapse": true,
"paging": true,
"info": false,
// other fields
// ...
});
// format checkboxes as switch buttons
$('.enable-disable').switchButton();
// others
// ...
});