我有一个<select>
并且每次用户更改其选择的选项时,我都想要一个不同的 jQuery Datatable 来绘制(使用隐藏的 DOM<table>
作为数据源):
<!-- Assume I have included jquery.dataTables.css and jquery.dataTables.js correctly. -->
<style>
#hidden-tables {
display: hidden;
}
</style>
<script type="text/javascript">
$(document).ready(function () {
$("#table1").dataTable();
$("#table2").dataTable();
});
</script>
<select id="my-sel">
<option selected="selected" id="opt1">Nothing selected</option>
<option id="opt1">Opt1</option>
<option id="opt2">Opt2</option>
</select>
<div id="hidden-tables">
<table id="table1">
<!-- Omitted for brevity -->
</table>
<table id="table2">
<!-- Omitted for brevity -->
</table>
</div>
<!-- When the user selects opt1 or opt2 in the "my-sel" <select>, then display its corresponding table here. -->
<div id="table-to-show"></div>
基本上,当页面加载时,我希望my-sel
选择显示“ Nothing selected ”并且不绘制表格。当用户选择“ Nothing selected ”以外的任何内容时,我希望适当的 jQuery DataTable 在table-to-show
div内绘制。提前致谢!