简单实用的jQuery分页插件twbs-pagination
在Web开发中,表格是一个很好展示数据的组件。当数据量大了,分页就不可避免了。分页不仅可以提高读取数据的性能,而且也会让用户体验更好。在前面雷雪松给大家介绍了Bootstrap Table这个插件。Bootstrap Table是集成了表格、分页、排序和搜索等功能。如果在特定情况下需要自己定义表格和分页,那么分页就是用jQuery分页插件twbs-pagination吧!twbs-pagination基于jQuery1.7.0或者更高版本,twbs-pagination可以自定义样式也可以很好的和bootstrap的分页组件结合。twbs-pagination的使用方法很简单。那么下面雷雪松给大家介绍一个简单实用的jQuery分页插件twbs-pagination。
1、定义一个ul或者div的容器
1 | <ul id="pagination" class="pagination-sm"></ul> |
2、自定义twb-sPagination配置,并调用
1 2 3 4 5 6 7 8 9 10 11 | $('#pagination').twbsPagination({ first: '首页',//首页 prev: '上一页',//上一页 next: '下一页',//下一页 last: '末页',//末页 totalPages: 35,//总页数 visiblePages: 7,//显示的页码数 onPageClick: function (event, page) {//点击页码触发的函数 console.log(page); } }); |
3、修改配置,重新生成
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | var $pagination = $('selector'); var defaultOpts = { totalPages: 20 }; $pagination.twbsPagination(defaultOpts); $.ajax({ ..., success: function (data) { var totalPages = data.newTotalPages; var currentPage = $pagination.twbsPagination('getCurrentPage');//获取当前页面 $pagination.twbsPagination('destroy');//销毁twbsPagination $pagination.twbsPagination($.extend({}, defaultOpts, { startPage: currentPage, totalPages: totalPages })); } }); |
2019年8月7日 下午1:51
看起来挺好使的样子,收藏了
2019年8月8日 下午11:07
文章不错支持一下吧
2021年11月26日 下午10:41
What you said was actually very reasonable. However, what about this?
suppose you typed a catchier post title? I am not saying your
information isn’t solid., however what if you added a title that grabbed a person’s attention? I mean 简单实用的jQuery分页插件twbs-pagination_雷雪松的博客 is a
little boring. You should peek at Yahoo’s front page and
note how they create news headlines to get people
interested. You might try adding a video or a related pic or two to
grab people interested about everything’ve written. In my opinion, it would make your
website a little bit more interesting.