今天就跟大家聊聊有关使用jquery怎么实现一个分页显示功能,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
html代码
<div class="am-g"> <div class="am-u-sm-12" id="listTag"> </div> </div>
js代码
$(function(){ showPage(1); }); function showPage(page){ $.ajax({ type:"GET", url:"<{$urlParent}>/newsManageList?cid=all", dataType:"json", success:function(data){ var newsTotalNum = data.length; //新闻记录的总条数 var pageNum = Math.ceil(newsTotalNum/<{$newsPageNum}>); //分页的总页数 var content = ' <form class="am-form" id="listContainer">' + '<table class="am-table am-table-striped am-table-hover table-main" id="newsList">' + '<thead>' + '<tr>' + '<th class="table-id">ID</th><th class="table-title">标题</th><th class="table-type">类别</th><th class="table-author am-hide-sm-only">作者</th><th class="table-date am-hide-sm-only">修改日期</th><th class="table-set">操作</th> ' + '</tr>' + '</thead>' + '<tbody>'; for(var i=((page-1)*<{$newsPageNum}>);i<(page*<{$newsPageNum}>)&&i<newsTotalNum;i++){ content += '<tr>' + '<td>'+(i+1)+'</td>' + '<td><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" >'+data[i].title+'</a></td>'+ '<td>'+data[i].name+'</td>' + '<td class="am-hide-sm-only">'+data[i].author+'</td>' + '<td class="am-hide-sm-only">'+data[i].time+'</td>' + '<td>' + '<div class="am-btn-toolbar"><div class="am-btn-group am-btn-group-xs">' + '<a href="<{$urlParent}>/newsUpdate?id='+data[i].id+'>" rel="external nofollow" class="am-btn am-btn-default am-btn-xs am-text-secondary"><span class="am-icon-pencil-square-o"></span> 编辑</a> ' + '<a href="<{$urlParent}>/newsDel?id='+data[i].id+'>" rel="external nofollow" class="am-btn am-btn-default am-btn-xs am-text-danger am-hide-sm-only"><span class="am-icon-trash-o"></span> 删除</a> ' + '</div></div>' + '</td>' + '</tr>'; } content += '</tbody></table>' + '<div class="am-cf">' + '共 '+newsTotalNum+' 条记录 / '+pageNum+'页' + '<div class="am-fr">' + '<ul class="am-pagination" id="page">'; //判断前面是否还有页面 if(page == 1){ content += '<li class="am-disabled"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" >«</a></li>'; }else{ content += '<li><a href="javascript:showPage('+(page-1)+')" rel="external nofollow" >«</a></li>'; } for(var i=1;i<=pageNum;i++){ if(i == page){ content += '<li class="am-active"><a href="javascript:showPage('+i+')" rel="external nofollow" rel="external nofollow" >'+i+'</a></li>'; }else{ content += '<li><a href="javascript:showPage('+i+')" rel="external nofollow" rel="external nofollow" >'+i+'</a></li>'; } } //判断后面是否还有页面 if(page == pageNum){ content += '<li class="am-disabled"><a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" >»</a></li>'; }else{ content += '<li><a href="javascript:showPage('+(page+1)+')" rel="external nofollow" >»</a></li>'; } content += '</ul>' + '</div>' + '</div><hr>' + '</form>'; $("#listTag").empty(); $("#listTag").append(content); } }); }
看完上述内容,你们对使用jquery怎么实现一个分页显示功能有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。