温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么在jquery中使用pagination.js实现分页

发布时间:2021-03-26 15:26:30 来源:亿速云 阅读:289 作者:Leah 栏目:web开发

怎么在jquery中使用pagination.js实现分页?针对这个问题,这篇文章详细介绍了相对应的分析和解答,希望可以帮助更多想解决这个问题的小伙伴找到更简单易行的方法。

添加下载的js和样式,主要是先添加jquery.js 再添加jquery.pagination.js,我这是下载好的,放在本地

<link rel="stylesheet" href="<%=path%>css/pagination.css" type="text/css"> <script type="text/javascript" src="<%=path%>js/jquery-1.11.3.js"></script> <script type="text/javascript" src="<%=path%>js/jquery.pagination.js"></script>

表格,用的是c标签,获取控制器传过来的值

<table width="1052" border=0 align=center cellpadding=2 cellspacing=1    bordercolor="#799AE1" class=tableBorder>    <tbody>     <tr>      <th align=center colspan=16 >商品显示</th>     </tr>     <tr align="center" bgcolor="#799AE1" >      <td width="10%" align="center" class=txlHeaderBackgroundAlternate>商品编号</td>      <td width="10%" align="center" class=txlHeaderBackgroundAlternate>商品大类</td>      <td width="10%" align="center" class=txlHeaderBackgroundAlternate>商品名称</td>      <td width="10%" align="center" class=txlHeaderBackgroundAlternate>商品规格</td>      <td width="10%" align="center" class=txlHeaderBackgroundAlternate>加权进价</td>      <td width="10%" align="center" class=txlHeaderBackgroundAlternate>当前售价</td>      <td width="10%" align="center" class=txlHeaderBackgroundAlternate>操作</td>     </tr>     <c:forEach items="${goodsS}" var="goods">      <tr bgcolor="#DEE5FA">       <td align="center" id="goodsId" class="txlrow"><c:out         value="${goods.goodsId}"></c:out></td>       <td align=center id="goodsType" class=txlrow><c:out         value="${goods.goodsType}"></c:out></td>       <td align=center id="goodsName" class=txlrow><c:out         value="${goods.goodsName}"></c:out></td>       <td align=center id="goodsContent" class=txlrow><c:out         value="${goods.goodsContent}"></c:out></td>       <td align=center id="goodsPrice" class=txlrow><c:out         value="${goods.goodsPrice}"></c:out></td>       <td align=center id="goodsSell" class=txlrow><c:out         value="${goods.goodsSell}"></c:out></td>       <td align=center class=txlrow> <input type="button" value="编辑"></td>      </tr>     </c:forEach>    </tbody>   </table> <!--分页显示--> <div id="Pagination"></div>

js

var limit=<%=request.getAttribute("limit")%>;//每页显示多少 条数据  var count=<%=request.getAttribute("count")%>//共多少条数据  var index=<%=request.getAttribute("index")%>;//当前记录数 $(function(){  $("#Pagination").pagination(count, {   items_per_page:limit, // 每页显示多少条记录   current_page: Math.ceil(index/limit), //当前页   num_display_entries:4, // 分页显示的条目数   next_text:"下一页",   prev_text:"上一页",   num_edge_entries:2, // 连接分页主体,显示的条目数   callback:handlePaginationClick  }); }); function handlePaginationClick(new_page_index, pagination_container) {   var path="<%=ppath%>/goodsManager/searchGoodsBylimit/" + new_page_index*limit;   $("#goodsForm").attr("action",path );   $("#goodsForm").submit();   return false; }

控制器

@RequestMapping(value = "/searchGoodsBylimit/{index}")  public String searchGoodsBylimitPst(Model model,    @ModelAttribute Goods goods, @PathVariable String index,    HttpServletRequest request) {   //索引   if (index == null || index.equals("")) {    index = "0";   //从服务器获取数据   List<Goods> goodsS = goodsService.selectGoods(goods,     Integer.parseInt(index), PageParam.limit);   if (goodsS != null) {    model.addAttribute("goodsS", goodsS);   } else {    model.addAttribute("resultMsg", "没有该商品");   }   //数据总条数   int count = goodsService.selectAllCount(goods);   model.addAttribute("index", index);   model.addAttribute("count", count);   model.addAttribute("limit", PageParam.limit);   System.out.println("第" + index + "数据开始显示" + goodsS.size() + "条记录");   return "goodsManager/showGoods";  }

效果图

怎么在jquery中使用pagination.js实现分页

关于怎么在jquery中使用pagination.js实现分页问题的解答就分享到这里了,希望以上内容可以对大家有一定的帮助,如果你还有很多疑惑没有解开,可以关注亿速云行业资讯频道了解更多相关知识。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI