jquery table动态展示后端数据
时间: 2023-08-05 08:09:03 浏览: 48
您可以使用 jQuery 插件 DataTables 来实现动态展示后端数据。下面是一个基本示例代码:
HTML 代码:
```html
<table id="myTable" class="display" style="width:100%">
<thead>
<tr>
<th>Name</th>
<th>Position</th>
<th>Office</th>
<th>Age</th>
<th>Start date</th>
<th>Salary</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
```
JavaScript 代码:
```javascript
$(document).ready(function() {
$('#myTable').DataTable({
"ajax": "/data.json", // 后端数据接口
"columns": [
{ "data": "name" },
{ "data": "position" },
{ "data": "office" },
{ "data": "age" },
{ "data": "start_date" },
{ "data": "salary" }
]
});
});
```
其中,`ajax` 选项指定后端数据接口,`columns` 选项指定表格列的数据源。后端需要返回一个包含表格数据的 JSON 对象。具体的数据格式可以参考 DataTables 的文档。