一个分页的小插件

这款分页的小插件,是我在网上看到了,是一个基于jq的代码写的动态获取的小插件,在这个插件中,发现了一些点击事件绑定的问题。所以在这个基础上做了一些小修改。有了这个小插件,动态获取分页效果。在实际开发中很是便利,

首先,以下的就是这个小插件的本身代码。这是从懒人之家里面下载的。赖人之家很多实用小插件很多的

<!DOCTYPE html>
<html lang="zh-cn" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8" />
<title>一个非常简单的jQuery分页插件</title>
<style>
*{ margin:0; padding:0; list-style:none;}
a{ text-decoration:none;}
a:hover{ text-decoration:none;}
.tcdPageCode{padding: 15px 20px;text-align: left;color: #ccc;}
.tcdPageCode a{
     display: inline-block;
     color: #B6BFD0;
     display: inline-block;
     height: 30px;
     line-height: 30px;
     padding: 0 10px;
     border: 1px solid #3A4466;
     margin: 0 2px;
     border-radius: 4px;
     vertical-align: middle;
     background: #0c2249;
}
.tcdPageCode a:hover{
     text-decoration: none;
     border: 1px solid #428bca;
}
.tcdPageCode span.current{
     display: inline-block;
     height: 30px;
     line-height: 30px;
     padding: 0 10px;
     margin: 0 2px;
     color: #fff;
     background-color: #b6bfd0;
     border: 1px solid #B6BFD0;
     border-radius: 4px;
     vertical-align: middle;
}
.tcdPageCode span.disabled{
     display: inline-block;
     height: 30px;
     line-height: 30px;
     padding: 0 10px;
     margin: 0 2px;
     color: #bfbfbf;
     background: #f2f2f2;
     border: 1px solid #bfbfbf;
     border-radius: 4px;
     vertical-align: middle;
}
</style>
</head>
<body>
<!-- 代码部分begin -->
    <div class="tcdPageCode">
    </div>
    <pre>
    调用方法:
    $(".tcdPageCode").createPage({
        pageCount:10,
        current:1,
        backFn:function(p){
            //单击回调方法,p是当前页码
        }
    });
    pageCount:总页数
    current:当前页
    </pre>
</body>
<script src="http://www.lanrenzhijia.com/ajaxjs/jquery.min.js"></script>
<script src="http://www.lanrenzhijia.com/ajaxjs/jquery.page.js"></script>
<script>
    $(".tcdPageCode").createPage({
        pageCount:6,
        current:1,
        backFn:function(p){
            console.log(p);
        }
    });
</script>
<!-- 代码部分end -->
</html>
以下的代码就是我在使用过程中,发生了一些bug,使用ajax请求分页,具体使用方式
function userAjax(index){
          $.ajax({
             url: "/edian_manage_web/user/getUserList",
             type: "POST",
             data:{currentPageIndex:index,eachPageSize:10},
             success: function (json){
                  userData(json);
                  userPager(json);
             },
             error: function () {
                 console.log("获取信息失败");
             }
         });
     }
     userAjax(1)
     function userData(json){
         var res = $.parseJSON(json)
         if(res.code==200&&res.data!==""){
              //对应的列表显示
              var _html = '';
              $.each(res.data.list,function(idx,ele){
                  _html += '<tr userId="'+ele.userId+'"><td>'+(idx+1)+'</td><td>'+ele.userName+'</td><td>'+ele.userPhone+'</td><td>'+ele.roleName+'</td><td>'+ele.isEnabled+'</td><td><span class="user-eidt eidt">编辑</span><span class="user-delete">删除</span></td>';
              });
              $('#user-list').html(_html);
              //删除事件
              var $delete = $('#user-list').find($('.user-delete'))
              $delete.on('click',function(){
                  //console.log('删除'+$(this).index())
                  var userId = $(this).parent('td').parent('tr').attr('userId')
                   //$(this).parent('td').parent('tr').remove()
                  $.ajax({
                       type:"post",
                          url:"/edian_manage_web/user/deleteUser",
                       dataType:'json',
                       data:{userId:userId},
                       success:function(json){
                           console.log('删除成功')
                           userAjax(1)
                       },
                       error:function(){
                            console.log('请求失败')
                       }
                  });
              })
              //编辑事件
              var $eidt = $('#user-list').find($('.user-eidt'))
              $eidt.on('click',function(){
                  var txt = $(this).text()
                  $('#add-user').modal()
                   $('#add-user').find('.modal-title').text(txt)
              })

         }
     }
     //分页
     function userPager(json){
         var res = $.parseJSON(json)
         $("#user-page").unbind() //使用解绑就可以解决掉每个页面点击跳转页面的bug
         cpage = res.data.pagination.currentPageIndex;
         totalpage = Math.ceil(res.data.pagination.count /res.data.pagination.eachPageSize);
         $("#user-page").createPage({
              pageCount:totalpage,
              current:cpage,
              backFn:function(p){
                  userAjax(p)
              }
         });
     }



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值