<script type="text/javascript">

        var curPage = 1;//当前页码
var total;//总页数 $(function () {
loadPage(curPage)
});
function loadPage(page) {
$.get("/API/News/GetByPage.ashx", { currentPage: page }, function (obj) {
total = obj.TotalPage; var ul = $("#newsList").empty();
$.each(obj.Info, function (i, e) { var li = $('<li style="color:#494053"> <a href="/HtmlContainer/News/' + e.newsId + '.html">' + e.newsTitle + '</a>' +
'<span style="float:right;">' + formatDate(e.newsAddtime.replace('T', ' '), "yyyy-MM-dd") + '</span> </li>');
li.appendTo(ul);
}); pageBarChange(page);
}, "json");
} function pageBarChange(page) { var frontSpac = 5,totalSpac=9;
curPage = page;//parseInt($("#pageNum").val()) + 1;
//$("#pageNum").val(curPage);
var start = 1;
if ((curPage - frontSpac) > 1 && (total - curPage) > frontSpac) {
start = curPage - frontSpac;
}
else if (total - curPage <= frontSpac) {
start = total - totalSpac;
} var html = '<a href="#" onclick="prev()"> << </a>';
for (var i = start; i <= start + totalSpac; i++) {
if (i == curPage) {
html += '<a class="current">' + i + '</a>';
continue;
}
html += ' <a class="pageNum" href="javascript:void(0)" relid=' + i + '>' + i + '</a>'; }
//加载最后一个按钮的情况
if (total - curPage <= frontSpac) {
var temp = (curPage + 1) > total ? total : (curPage + 1);
html += ' <a class="pageNum" href="javascript:void(0)" relid=' + temp + '> </a><a onclick="next()" href="javascript:void(0)"> >> </a>';
}
else {
html += '... <a class="pageNum" href="javascript:void(0)" relid=' + total + '>' + total + '</a> <a onclick="next()" href="javascript:void(0)"> >> </a>';
} $("#pageBar").empty().append($(html)); $("#pageBar .pageNum").bind("click", function () {
var page1 = parseInt($(this).attr("relid"));
loadPage(page1);
// pageBarChange(page1);
}); } function prev() {
if ((curPage - 1) <= 0) {
return;
}
loadPage(--curPage);
// pageBarChange(--curPage);
} function next() {
if ((curPage + 1) > 18) {
return;
}
loadPage(++curPage);
// pageBarChange(++curPage);
} </script>

效果:

页码分页的前端写法

最新文章

  1. web请求的拦截与处理
  2. nodejs的初学
  3. 在同台电脑上再次安装MySql需要注意的事项
  4. poj 3067 - Japan(树状数组)
  5. Language Tool ,a plugin for TeXStudio
  6. ural 1145. Rope in the Labyrinth
  7. PS CS5
  8. VS2008编写MFC程序--使用opencv2.4()
  9. PC端Web项目开发流程
  10. C#爬虫系列(一)——国家标准全文公开系统
  11. 解析Visual C# 7.2中的private protected访问修饰符
  12. href的理解
  13. 使用mybatis注解@Options实现添加记录时返回主键值
  14. 我写的Java相关的文章
  15. Python中生成器generator和迭代器Iterator的使用方法
  16. Python split()
  17. T-SQL目录汇总1
  18. 自定义控件?试试300行代码实现QQ侧滑菜单
  19. Python:zip()函数
  20. 5 - django-csrf-session&amp;cookie

热门文章

  1. ado.net增删改查操作
  2. ThinkPHP去重 distinct和group by
  3. Uva 11059 Maximum Product
  4. fzu月赛 2203 单纵大法好 二分
  5. wpf中dropdownButton控件下拉居中。。。
  6. DP ZOJ 2745 01-K Code
  7. HBase Shell 常见操作
  8. C# 词法分析器(二)输入缓冲和代码定位
  9. WPF ComboBox Binding
  10. Eclipse: Resource is out of sync with the file system when publishing to tomcat server on Eclipse