【练习】基于Bootstrap点击分页
2020-05-21 16:07
197 查看
脑子不是很好使,钻研了一天鼓捣出来傻瓜式写法,记录以下自己的代码,应该没有什么参考意义
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <link rel="stylesheet" href="bootstrap.min.css"> <title>Document</title> </head> <body> <nav aria-label="Page navigation"> <ul class="pagination"> <li class="Previous"> <a aria-label="Previous"> <span aria-hidden="true">«</span> </a> </li> <li class="Next"> <a aria-label="Next"> <span aria-hidden="true">»</span> </a> </li> </ul> </nav> </body> <script src="jquery-3.4.1.min.js"></script> <script src="bootstrap.min.js"></script> <script> var thispages=0; thispage=1;pages=10;page=0;pagehtml='';hidepagehtml='<li class="pagehide disabled"><a>...</a></li>'; while(page<pages){ page++; pagehtml+='<li class="page"><a>'+page+'</a></li>'; } $('.Previous').after(pagehtml) $('.pagination li.page').eq(0).addClass('active'); //识别上一页下一页状态 function getupdown(){ if(thispage==1){ $('.Previous').addClass('disabled'); }else{ $('.Previous').removeClass('disabled'); } if(thispage==pages){ //pages=总页数; $('.Next').addClass('disabled'); }else{ $('.Next').removeClass('disabled'); } } //点击切换 $('.pagination li.page').click(function(){ $(this).addClass('cur').siblings('li').removeClass('cur'); thispage=$('.cur a').text(); getpage(); getupdown(); hidepages(); }); getupdown(); //识别切换 function getpage(){ thispages=thispage-1; $('.pagination li.page').eq(thispages).addClass('active').siblings('li').removeClass('active') } //点击下一页 $('.Next').click(function(){ if(thispage!=pages){ thispage++; } getupdown(); getpage(); hidepages(); }); //点击上一页 $('.Previous').click(function(){ if(thispage!=1){ thispage--; } getupdown(); getpage(); hidepages(); }); //页码隐藏算法 function hidepages(){ $('.active').prevAll().show(); $('.active').nextAll().show(); $('.pagehide').remove(); if((thispages-1)>=3){ if((pages-thispage-1)<3){ $('.active').prev().prev().prev().prev().prevAll().hide(); $('.Previous').show(); $('.pagination li').eq(1).show(); $('.active').prev().prev().prev().prev().before(hidepagehtml); }else{ $('.active').prev().prev().prevAll().hide(); $('.Previous').show(); $('.pagination li').eq(1).show(); $('.active').prev().prev().before(hidepagehtml); } }; if((pages-thispage-1)>=3){ if(thispage<3){ $('.active').next().next().next().next().nextAll().hide(); $('.Next').show(); $('.pagination li').eq(-2).show(); $('.active').next().next().next().next().after(hidepagehtml); }else{ $('.active').next().next().nextAll().hide(); $('.Next').show(); $('.pagination li').eq(-2).show(); $('.active').next().next().after(hidepagehtml); }; getpage(); } } hidepages(); </script> </html>
相关文章推荐
- 基于bootstrap的mvcpager简单分页
- [JavaScript]基于Bootstrap+jQuery构建前端分页工具
- 基于Metronic的Bootstrap开发框架经验总结(18)-- 在代码生成工具Database2Sharp中集成对Bootstrap-table插件的分页及排序支持
- Maven 基于SSM框架的增删改(使用了bootstrap的模态框,分页插件pagehelper, ajax等,附sql文件)
- 基于bootstrap的分页插件bootstrap-paginator
- 基于Metronic的Bootstrap开发框架经验总结 --列表分页处理和插件JSTree的使用
- 基于bootstrap的分页代码
- 基于bootstrap的仿站练习01
- 基于Metronic的Bootstrap开发框架经验总结(16)-- 使用插件bootstrap-table实现表格记录的查询、分页、排序等处理
- 基于Bootstrap仿淘宝分页控件实现
- 基于ASP.NET、Entity Framework、Bootstrap的分页
- 基于Metronic的Bootstrap开发框架经验总结(2)--列表分页处理和插件JSTree的使用
- 基于Bootstrap的Asp.net Mvc 分页的实现(转)
- 分享几款基于bootstrap和jquery的分页插件
- 开发基于SpringBoot和BootStrap的全栈论坛网站(五):完成首页展示以及分页功能
- 通用分页 (基于jquery、bootstrap)
- 2014.6.6 jquery 点击选中/取消 prop | Bootstrap 基于标签的导航实例
- (转)基于Metronic的Bootstrap开发框架经验总结(2)--列表分页处理和插件JSTree的使用
- 基于bootstrap + velocity的分页实现
- 分页插件(基于jq和bootstrap)