Bootstrap jquery.twbsPagination.js动态页码分页实例代码
Bootstrap风格的分页控件自适应的:
参考网址:分页参考文档
1.风格样式:
2.首先引入js文件jQuery.twbsPagination.js
<span style="font-size:14px;"><script type="text/javascript" src="plugins/page/jquery.twbsPagination.js"></script></span>
3.html页面
<span style="font-size:14px;"><div class="text-center"> <ul id="pagination-log" class="pagination-sm"></ul> </div></span>
4.初始化
<span style="font-size:14px;">// 初始化加载信息数据 function initUserlogData() { //重置分页组件否则保留上次查询的,一般来说很多问题出现与这三行代码有关如:虽然数据正确但是页码不对仍然为上一次查询出的一致 $('#pagination-log').empty(); $('#pagination-log').removeData("twbs-pagination"); $('#pagination-log').unbind("page"); //将页面的数据容器制空 $("#messagebody").empty(); //设置默认当前页 var pagenow = 1; //设置默认总页数 var totalPage = 1; //设置默认可见页数 var visiblecount = 5; //加载后台数据页面 function loaddata() { $.ajax({ url : "/tqyh/showUserloginfo", type : "post", data : { "currentpage" : pagenow }, dataType : "json", success : function(data) { var htmlobj = ""; totalPage = data.page.totalPage;//将后台数据复制给总页数 totalcount = data.page.totalCount; $("#userlogbody").empty(); $.each(data.userlog, function(index, userlog) { htmlobj = htmlobj + "<tr>" + "<td><input type='checkbox'/></td>" + "<td>" + userlog.toUserName + "</td>" + "<td>" + userlog.fromUserName + "</td>" + "<td>" + userlog.createTime + "</td>" + "<td>" + userlog.eventType + "</td>" ; if(userlog.eventType=="LOCATION"){ htmlobj = htmlobj + "<td><button name="+ userlog.eventType + " location='"+userlog.details+"' class='btn btn-danger btn-lg btn-sm no-radius' data-toggle='modal' data-target='#myModal' onclick='showmodal(this)' >" + "<i class='glyphicon glyphicon-map-marker'> LOCATION</i></button></td>"; }else{ htmlobj = htmlobj +"<td>"+ userlog.details + "</td>"; }; htmlobj = htmlobj + "</tr>"; $("#userlogbody").append(htmlobj); htmlobj = ""; }); //后台总页数与可见页数比较如果小于可见页数则可见页数设置为总页数, if (totalPage < visiblecount) { visiblecount = totalPage; } $('#pagination-log').twbsPagination({ totalPages : totalPage, visiblePages : visiblecount, version : '1.1', //页面点击时触发事件 onPageClick : function(event, page) { // 将当前页数重置为page pagenow = page //调用后台获取数据函数加载点击的页码数据 loaddata(); } }); }, error : function(e) { alert("s数据访问失败") } }); } //函数初始化是调用内部函数 loaddata(); };</span>
6.后台的json数据返回就行
7.结果截图:
相关推荐
K先生 2020-11-10
wushengyong 2020-10-28
西瓜皮儿的皮儿 2020-09-07
molong0 2020-08-03
jokewinl 2020-07-18
田有朋 2020-07-05
80530895 2020-07-05
javamagicsun 2020-06-21
liangwenrong 2020-06-17
molong0 2020-06-16
xiuyangsong 2020-06-03
jaylong 2020-06-02
EdShao 2020-05-29
晨曦之星 2020-05-29
dreamhua 2020-05-10
smalllove 2020-05-09
liqiancao 2020-05-08
Dullonjiang 2020-05-06
GechangLiu 2020-05-04