列表數據後端分頁,點擊頁碼無刷新更新表格區域。
$.get('/api/list?page=2', renderTable)。{data: [...], total: 100, page: 2, pageSize: 10}。tbody → 循環拼接 tr 字符串 → tbody.innerHTML = html 或 $(tbody).html(html)。
// 頁碼委託事件
$('#pagination').on('click', 'a.page-link', function(e) {
e.preventDefault();
const page = $(this).data('page');
loadPage(page);
});
function loadPage(page) {
$.getJSON('/api/data', {page: page, size: 10}, function(res) {
// 1. 渲染表格
let html = '';
res.data.forEach(item => {
html += `${item.id} ${item.name} ... `;
});
$('#data-tbody').html(html);
// 2. 重新渲染分頁條
renderPager(res.page, res.totalPages);
});
}