基于jquery封装的一个js分页
代码如下:
(function ($) {
var pagefunc = function pagefunc() { }
$.pagefunc = function (total, pagesize, curpagenum, funurl) {
if (pagesize == "" || pagesize == null || pagesize == undefined) {
pagesize = 10;
}
if (curpagenum == "" || curpagenum == null || curpagenum == undefined) {
curpagenum = 1;
}
//计算总页数
total = parseint(total); //总记录数
pagesize = parseint(pagesize); //每页显示数
curpagenum = parseint(curpagenum); //当前页
//总页数
var allpage = math.floor(total / pagesize);
if (total % pagesize != 0) {
allpage++;
}
var navhtml = "";
if (curpagenum <= 0)
curpagenum = 1;
if (allpage > 1) {
if (curpagenum != 1) {
//处理首页连接
navhtml += "<span><a href=\"javascript:" + funurl + "('1')\" >|<</a></span> ";
}
if (curpagenum > 1) {
//处理上一页的连接
navhtml += "<span><a href=\"javascript:" + funurl + "('" + (curpagenum - 1) + "')\" ><<</a></span> ";
}
else {
navhtml += "<span class=\"disabled\"><<</span> ";
}
var currint = 5;
for (var i = 0; i <= 10; i++) {
//一共最多显示10个页码,前面5个,后面5个
if ((curpagenum + i - currint) >= 1 && (curpagenum + i - currint) <= allpage)
if (currint == i) {
//当前页处理
navhtml += "<span lass=\"current\">[" + curpagenum + "]</span> ";
}
else {
//一般页处理
var n = curpagenum + i - currint;
navhtml += "<a href=\"javascript:" + funurl + "('" + (parseint(n)) + "')\">" + n + "</a> ";
}
}
if (curpagenum < allpage) {
//处理下一页的链接
navhtml += "<span><a href=\"javascript:" + funurl + "('" + (parseint(curpagenum) + 1) + "')\">>></a></span> ";
}
else {
navhtml += "<span class=\"disabled\">>></span> ";
}
if (curpagenum != allpage) {
navhtml += "<span><a href=\"javascript:" + funurl + "('" + allpage + "')\" >>|</a></span> ";
}
}
navhtml += "<span>[" + curpagenum + "/" + allpage + "]</span> ";
return navhtml;
};
})(jquery);
下边是调用方法:
代码如下:
function querylist(curpage) {
if (curpage == "" || curpage == null || curpage == undefined) {
curpage = 1;
}
var pagesize = 10;
var countys = $("#countys").val(); //县
var enddate = $("#enddate").val(); //结束时间
var begindate = $("#begindate").val(); //开始时间
$.ajax({
url: "",
type: "post",
data: { "countys": countys, "enddate": enddate, "begindate": begindate, "curpage": curpage, "pagesize": pagesize },
datatype: "json",
error: function (xhr, status, errmsg) { window.location.href = "/commonerror/index/" + errmsg.code + "?txt=" + errmsg.msg; },
success: function (mydata) {
var str = "";
$.each(mydata.tdata, function (i, item) {
str += "<tr>"
str += "<td>" + $.formatdatetime(item.controlbegintime, false) + "</td>";
str += "<td>" + $.formatdatetime(item.controlendtime, false) + "</td>";
str += "<td>" + item.name + "</td>";
str += "<td>" + item.platenumber + "</td>";
str += "<td>" + item.controldept + "</td>";
if (item.isall == "0") {
str += "<td>全县布控</td>";
}
else {
str += "<td>按卡口点布控</td>";
}
str += "<td>" + item.isall == "0" ? "全县布控" : "按卡口点布控" + "</td>";
str += "<td>修改</td>";
str += "<td>删除</td>";
str += "<td>详细</td>";
str + "</tr>";
});
$("#srh_rslt tbody").html(str);
$(".pagination").html($.pagefunc(mydata.total, pagesize, curpage, "querylist"));
}
});
}
下一篇: 原型模式
推荐阅读
-
基于innerHTML中的script广告实现代码[广告全部放在一个js里面] 原创
-
基于jQuery实现一个marquee无缝滚动的插件
-
一个基于ROW_NUMBER()的通用分页存储过程代码
-
JS/jquery实现一个网页内同时调用多个倒计时的方法
-
基于innerHTML中的script广告实现代码[广告全部放在一个js里面] 原创
-
基于jQuery实现一个marquee无缝滚动的插件
-
JS实现点击生成UUID的方法完整实例【基于jQuery】
-
PHP封装的一个支持HTML、JS、PHP重定向的多功能跳转函数
-
基于vue-upload-component封装一个图片上传组件的示例
-
TimergliderJS 一个基于jQuery的时间轴插件