php中用js分页案例

<div id="adminmaincontent">
    
    <div class="pagenav w100">
           <div class="float">

        <div class="e5"></div><div class="pre" name="pre" style=" float:left;" onclick="paging_up()">上一页|</div><div class="next" name="next" style=" float:left;" onclick="paging_down();">下一页|</div></div>

        </div>
    </div>


<table  class="w100" cellspacing="0" cellpadding="0" border="0" id="datatable">
        <thead>
          <tr>
            <td class="td1">序号</td>
            <td class="td1">商品id</td>
            <td class="td1">商品名称</td>
            <td class="td1">评价类容</td>
            <td class="td1">晒单</td>
            <td class="td1">评论时间</td>
            <td class="td1">评论人</td>
          </tr>
        </thead>
        <tbody id='listcontent'>




        </tbody>
        <tfoot>
          <tr>
            <td class="td1" id="commentid">序号</td>
            <td class="td1">商品id</td>
            <td class="td1">商品名称</td>
            <td class="td1">评价类容</td>
            <td class="td1">晒单</td>
            <td class="td1">添加时间</td>
            <td class="td1">添加人</td>
          </tr>
        </tfoot>
      </table>
</div>
<script>
var paging_Index = 1; //当前页
var paging_size = 1; //每页条数
    //总数
    var numData = <?php echo $CommentData;?>;

   // console.log(numData);
    var num = numData.length;
    //总页数
    var page = Math.ceil(num / paging_size);
   
function feedback_list_paging() {
   

    
    //当前页数是不是小雨第一页
    if (paging_Index <= 0) paging_Index = 1;
    var startRow = (paging_Index - 1) * paging_size; //开始显示的行
    var endRow = paging_Index * paging_size; //结束显示的行
    
    endRow = (endRow > num) ? num : endRow;
    
    //遍历数据
    var data = {
    numData: []
    };
    
    var listdata = '';
    
    for (var i = startRow; i < endRow; i++) {

        
         listdata +='<tr><td class="td1">'+numData[i]['Comment']['id']+'</td>';
         listdata +='<td class="td1">'+numData[i]['Comment']["goods_id"]+'</td>';
         listdata +='<td class="td1">'+numData[i]['Comment']["goods_name"]+'</td>';
         listdata +='<td class="td1">'+numData[i]['Comment']["content"]+'</td>';
         listdata +='<td class="td1">';

        if(numData[i]['Comment']["bask_single"]==''){

            listdata +='无图片';

        }else{
            
            listdata +='<a href="<?php echo $this->Html->url("/Comments/tupianji/");?>'+numData[i]['Comment']['id']+'">查看图片集</a>';
        }
         
         listdata +='</td>';
         listdata +='<td class="td1">'+GetDateStr(numData[i]['Comment']["add_time"])+'</td>';

         listdata +='<td class="td1">'+numData[i]['Comment']["user_name"]+'</td>';
        data['numData']['num'] = page; //总页数
        data['numData']['paging_Index'] = paging_Index; //当前页数
       

    }
    $('#listcontent').html(listdata);

}
//投诉建议分页上一页
function paging_up() {
    
    --paging_Index;
    if (paging_Index <= 0) {
        paging_Index = 1;
        alert("当前已经是第一页");
        return false;
    }
    
  feedback_list_paging();
}
//投诉建议分页下一页
function paging_down() {
    ++paging_Index;
    
    //总数
   // var num = fedback_data["CommentData"].length;
    //总页数
    var page = Math.ceil(num / paging_size);
    
    if (paging_Index > page) {
        paging_Index = page;
         alert("当前已经是最后一页");

        return false;
    }
     feedback_list_paging();
    
}
$(function(){
    feedback_list_paging();
})

posted @ 2014-04-09 15:36  无法抹去的记忆  阅读(303)  评论(0编辑  收藏  举报