根據項目需求,傳入 起始值,限制值,將該代碼稍作修改,現 只貼出最關鍵部分
// 臨時中間頁碼 當頁碼數量大于顯示的最大按鈕數時使用
var tempStartIndex = options.pageIndex - Math.floor(options.maxButtonCount / 2) + 1;
// 計算終止頁碼
var endIndex = Math.min(options.totalPages,Math.max(0,tempStartIndex) + options.maxButtonCount) - 1;
var startIndex = Math.max(0,endIndex - options.maxButtonCount + 1);
1. 通過計算 中間最多 要顯示的按鈕數 取其一般,做差補,
2. 通過中間值,算出中間按鈕結束值
3. 通過結束值,算出中間按鈕起始值,做差補