$.fn.wsinglePagination = function(_opts){ var opts = $.extend({ base : "", durl : "", mdiv : "", pdiv : "", perPage : 6, param : {}, infoUrl : "" },_opts); var status = { recordCount : 0, totalPage : 0 }; return this.each(function(){ var currPage,panel = $(this).css({'text-align':'center'}); function _loadData(json) { var result = json.DATALIST; var num = (currPage-1)*opts.perPage; var html = ""; $.each(result,function(i,item) { if(item.big_category == 1) { html += '

'+item.title+'

时间:'+item.update_time+'

'+item.content+'

'+item.tag+'
'; } else if(item.big_category == 2) { html += '

'+item.title+'

时间:'+item.update_time+'

'+item.content+'

'; } }); if(opts.mdiv)$('#'+opts.mdiv).append(html); _render(); if(opts.dataHandler) { opts.dataHandler(html); } } function _loadPage(cpage,json){ panel.html("加载中").unbind('click'); currPage = cpage; if(!json) { opts.param = $.extend(opts.param,{currPage:cpage,pageSize:opts.perPage}); $.post(opts.durl,opts.param,function(data){ _loadData(data); },'json'); } else { _loadData(json); } } function _gotoPage(page){ return function(){ _loadPage(page); }; } function _render(){ if(currPage == status.totalPage){ panel.html("没有了").unbind('click'); }else{ panel.html("加载更多").bind('click',_gotoPage(currPage+1)); } } opts.param = $.extend(opts.param,{currPage:1,pageSize:opts.perPage}); panel.html("加载中").unbind('click'); //开始执行 $.post(opts.durl,opts.param,function(json){ //每次新的查询,都移除panel的click事件 panel.unbind('click'); //设置翻页 var total = json.total; if(total==0){ panel.html("暂无数据").show(); }else{ status.recordCount = total; status.totalPage = Math.ceil(total/opts.perPage); //放置第一页 _loadPage(1,json); //if(total>opts.perPage){ // $('#'+opts.pdiv).show(); //}else{ // $('#'+opts.pdiv).hide(); //} $('#'+opts.pdiv).show(); } },'json'); }); };