jQuery实现的分页功能示例

2020-05-27 18:05:27易采站长站整理

i = configs.PageIndex - k;
j = configs.PageIndex + k + 1;
a = 1;
b = 1;
if ((configs.showPageCount - 1) % 2) {
i -= 1
}
}
}
else {
i = 2;
j = totalpage;
}
if (b) {
tmp += "..."
}
for (; i < j; i++) {
tmp += "<a>" + i + "</a>"
}
if (a) {
tmp += " ... "
}
if (totalpage > 1) {
tmp += "<a>" + totalpage + "</a>"
}
if (configs.PageIndex < totalpage) {
tmp += "<a>></a>"
} else {
tmp += "<a class="no">></a>"
}
tmp += "<input type="text" /><a>Go</a>"
var pager = this.html(tmp)
var index = pager.children('input')[0] pager.children('a').click(function() {
var cls = $(this).attr('class');
if (this.innerHTML == '<') {
if (cls != 'no') {
configs.onPageClick(configs.PageIndex - 2)
}
} else if (this.innerHTML == '>') {
if (cls != 'no') {
configs.onPageClick(configs.PageIndex)
}
} else if (this.innerHTML == 'Go') {
if (!isNaN(index.value)) {
var indexvalue = parseInt(index.value);
indexvalue = indexvalue < 1 ? 1 : indexvalue
indexvalue = indexvalue > totalpage ? totalpage : indexvalue
configs.onPageClick(indexvalue - 1)
}
} else {
if (cls != 'cur') {
configs.onPageClick(parseInt(this.innerHTML) - 1)
}
}
}).each(function() {
if (configs.PageIndex == parseInt(this.innerHTML)) {
$(this).addClass('cur')
}
})
}

③ 初始化使用


$(document).ready(function() {
//设置分页信息
var pageOptions = {
AllowPaging: true,
PageIndex: 1, //设置当前页码
PageSize: 15, //设置分页大小
RecordCount: 1092, //设置数据总数
TotalPage: 73, //设置总页数
showPageCount: 4,
onPageClick: function(pageIndex) {
alert("您点击了第" + parseInt(pageIndex + 1) + "页"); //自定义您的翻页事件
return false;
}
}
//初始化分页栏
$('.g-pagerwp .g-pager').css('visibility', 'visible').pageBar(pageOptions);
})

更多关于jQuery相关内容感兴趣的读者可查看本站专题:《jQuery扩展技巧总结》、《jQuery表格(table)操作技巧汇总》、《jQuery常见经典特效汇总》、《jquery选择器用法总结》及《jQuery常用插件及用法总结》

希望本文所述对大家jQuery程序设计有所帮助。