js实现的分页

1. < html>
2.
3. < body>
4.
5. < span id=contents>


6. < span id=splitpage>
7.
8. < script type="text/javascript">
9.
10. _currentPage = 2;//设置当前页码
11. _indexContainer = document.all.splitpage;//设置存放分页索引号的容器
12. _contentContainer = document.all.contents;//设置存放分页内容的容器
13. _totalPages = 0;//初始化总页数
14. (function pageLoad() {
15. _indexContainer.innerHTML =pageNo(100,2,10,7).join(" ");
16. var str="getR("+3+")";
17. goToPage(100, 3, 10,7,str);
18. })();
19.
20. //返回页码对象
21. function pageNo(counts, currentPage, perPage,showIndex,str) {
22. var perPage = perPage ? perPage : 5;


23.
24. var pages=0;
25. pages=counts/perPage+1;
26. var pageIndex = [];
27. //插入第一页标识
28. if(currentPage==1){
29. pageIndex.push(" 《《 《 ");
30. }else{//注意这里是 A标签 我把前面的<去掉了 因为 加上后会让系统会自动识别成连接无法正常显示代码
31. var str1="a href=\"javascript:goToPage("+counts+", "+1+", "+perPage+","+showIndex+",'"+str+"')\">《《 a href=\"javascript:goToPage("+counts+", "+(currentPage-1>0?currentPage-1:1)+", "+perPage+","+showIndex+",'"+str+"')\"> 《 ";
32. pageIndex.push(str1);
33. }
34.
35. var cyclCousnts=parseInt(showIndex/2);
36.
37. for(var i=1;i<=showIndex;i++){
38. var tmpPage=currentPage>=cyclCousnts?currentPage-cyclCousnts+i-1:i;
39. if(currentPage==tmpPage)
40. pageIndex.push("font color=\"red\">"+tmpPage+"");
41. else if(tmpPage>pages)
42. continue;
43. else if(tmpPage<1)
44. continue;
45. else{//注意这里是 A标签 我把前面的<去掉了 因为 加上后会让系统会自动识别成连接无法正常显示代码
46. var str1="a href=\"javascript:goToPage("+counts+", "+tmpPage+", "+perPage+","+showIndex+",'"+str+"')\">"+tmpPage+"";
47. pageIndex.push(str1);
48. }
49. }
50. if(currentPage==pages){
51. pageIndex.push(" 》 》》");
52. }else{//注意这里是 A标签 我把前面的<去掉了 因为 加上后会让系统会自动识别成连接无法正常显示代码
53. var str1="a href=\"javascript:goToPage("+counts+", "+(currentPage+1>pages?currentPage:currentPage+1)+", "+perPage+","+showIndex+",'"+str+"')\">》 a href=\"javascript:goToPage("+counts+", "+pages+", "+perPage+","+showIndex+",'"+str+"')\">》》 ";
54. pageIndex.push(str1);
55. }
56.
57. return pageIndex;
58. }
59.
60.
61. function goToPage(counts, currentPage, perPage,showIndex,str) {
62. _contentContainer.innerHTML = eval(str);
63. _indexContainer.innerHTML = pageNo(counts, currentPage, perPage,showIndex,str).join(" ");
64. }
65.
66. function getRecord(currentPage){
67. return "the current pagaea is:"+currentPage;
68. }
69.
70. function getR(currentPage){
71. return "the current page by eval is:"+currentPage;
72. }
73.
74. < /script>
75. < /body>
76. < /html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值