var getPages = function (current, total) { var range = 1; var min = Math.max(current - range, 1), max = Math.min(current + range, total); max = min == 1 ? Math.min(1 + 2 * range, total) : max; min = max == total ? Math.max(max - 2 * range, 1) : min; var html = []; if (current == min) { //html.push("首页上一页"); } else { html.push("
  • 首页
  • "); html.push("
  • 上一页
  • "); } for (var i = min; i <= max; i++) { html.push("
  • " + i + "
  • "); } if (current == max) { //html.push("下一页尾页"); } else { html.push("
  • 下一页
  • "); html.push("
  • 尾页
  • "); } if (min > 0) { html.push("
  • " + total + "
  • "); } return html.join(""); } var pageAssist = { setup: function (options) { var $container = $(options.container); $(document).on("click", options.delegate, options.pageClick); return function (current, total) { if (total <= 1) { $container.html(""); return; } $container.html(getPages(current, total)); } } } var pageAssist1 = { setup: function (options) { var $container = $(options.container); $(document).off("click",options.delegate).on("click", options.delegate, options.pageClick); return function (current, total) { if (total <= 1) { $container.html(""); return; } $container.html(getPages(current, total)); } } }