码迷,mamicode.com
首页 > Web开发 > 详细

jquery 分页

时间:2015-01-26 16:45:49      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

最近有点无所事事,无聊之极!

 

啊啊啊,表示很痛苦!

                <div id="tablist_01" class="list_tab">
		  <table width="765" border="0" cellspacing="0" cellpadding="0" class="list04">
          </table>
		  <div class="pages"><a href="javascript:void(0);" onclick="pre(event);"><<上一页</a><a href="javascript:void(0);" onclick="nxt(event);">下一页>></a></div>
		  </div>

  

          function investmentGrid(page) {
                var investmentUrl = "/tradeRecord/getTradeRecordList";
                var investment = ajax(investmentUrl,{customer_id:customerid, page:page}, false);
                var total = investment.total;
                var rows = investment.rows;
                var tab = $("#tablist_01 table");
                $.each(rows, function(index, row) {
        var html = ‘<tr>‘;
        if(page == 1){
            html += ‘<td>‘ + (index+1) + ‘</td>‘;
        }else{
            html += ‘<td>‘ + ((index+1)+((page-1)*10)) + ‘</td>‘;
        }
        tab.append(html);
        });
            // 分页
    $("#tablist_01 .pages").html(‘<a href="javascript:void(0);" onclick="pre(event);">&lt;&lt;上一页</a><a href="javascript:void(0);" onclick="nxt(event);">下一页&gt;&gt;</a>‘);
    var footer = getFooter(total, page, "investmentGrid");
    $("#tablist_01 .pages").find("a:first").after(footer);
              
          }

分页

          function getFooter(total, page, callback, pageSize) {
    var footer = ‘‘;
    pageSize = pageSize ? pageSize : 10;
    for (var i = 0; i < total / pageSize; i++) {
        var p = i + 1;
        if (p == 1 || p == parseInt(total / pageSize)) {
        } else if (page - p > 4) {
            continue;
        } else if (page - p == 4) {
            footer += "...";
            continue;
        } else if (p - page == 6) {
            footer += "...";
            continue;
        } else if (p - page > 6) {
            continue;
        }
        footer += (p == page ? "<b>" + p + "</b>" : ‘<a href="javascript:void(0);" onclick="jump(‘ + p + ‘, ‘ + callback + ‘)">‘ + p + ‘</a>‘);
    }
    return footer;
}


          function pre(event) {//上一页
    event = event ? event : window.event; 
    var obj = event.srcElement ? event.srcElement : event.target;
    var $p = $(obj).parent().find("b");
    if ($p.length > 0) {
        var page = $p.html();
        if (page == 1) {
            alert("已经是第一页!");
        } else {
            $p.prev("a").trigger("click");
        }
    }
}

function nxt(event) {//下一页
    event = event ? event : window.event; 
    var obj = event.srcElement ? event.srcElement : event.target;
    var $p = $(obj).parent().find("b");
    if ($p.length > 0) {
        if ($p.next("a")[0] == $(obj)[0]) {
            alert("已经是最后一页!");
        } else {
            $p.next("a").trigger("click");
        }
    }
}


function jump(page, callback) {
    callback(page);
}

Java,后台代码查询:

 public Map<String,Object> getList(AccountStreamVoBean accStrVo){
    Map<String, Object> map = new HashMap<String, Object>();
    List<Map<String, Object>> list = this.cusAccDao.getAccStream(accStrVo);//查询数据
    int count = cusAccDao.getAccStreamCount(accStrVo);//查询共有多少条数
    map.put("rows", list);
    map.put("total", count);
    return map;
 }

没心情!

jquery 分页

标签:

原文地址:http://www.cnblogs.com/1246447850qqcom/p/4250610.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!