///分页工具生成
//dataEle-数据盒子
//pageEle-分页盒子
//obj-调用方法传递
//url-传递方法内参
//cndt-传递方法内参
//ishow-传递方法内惨
pagerTool: function(dataEle, pageEle, obj, url, cndt, ishow) {
var total = $(pageEle).attr('total') - 0; //总数
var rowcount = $(pageEle).attr('rowcount') - 0; //页尺寸
var index = $(pageEle).attr('index') - 0; //页码
var count = total % rowcount == 0 ? total / rowcount: Math.floor(total / rowcount) + 1; //总页数
var html = '';
Html += '<p class="page">';
Html += '<a href="javaScript:void(0)" class="prePage">上一页</a>';
//总量大于15页时,生成转跳选择框并隐藏多余页码按钮
if (count > 15) {
//优化视觉效果
if (index <= 8) {
for (var i = 1; i <= 15; i++) {
if (index != i) {
Html += '<a href="javaScript:void(0)" class="nowPage">' + i + '</a>';
} else {
Html += '<a href="javaScript:void(0)" class="nowPage" style="background:#ACDDEA; color:#226F83; border:#93D3E4 1px solid;">' + i + '</a>';
}
}
} else {
var s = index - 8 + 1;
if (s + 14 > count) {
var c = s + 14 - count;
s = s - c;
}
for (var i = s; i <= s + 14; i++) {
if (index != i) {
Html += '<a href="javaScript:void(0)" class="nowPage">' + i + '</a>';
} else {
Html += '<a href="javaScript:void(0)" class="nowPage" style="background:#ACDDEA; color:#226F83; border:#93D3E4 1px solid;">' + i + '</a>';
}
}
}
Html += '<a href="javaScript:void(0)">转到</a>';
Html += '<select class="nowPage">';
for (var i = 1; i <= count; i++) {
Html += '<option>' + i + '</option>';
}
Html += '</select>';
Html += '<a href="javaScript:void(0)">页</a>';
} else {
for (var i = 1; i <= count; i++) {
if (index != i) {
Html += '<a href="javaScript:void(0)" class="nowPage">' + i + '</a>';
} else {
Html += '<a href="javaScript:void(0)" class="nowPage" style="background:#ACDDEA; color:#226F83; border:#93D3E4 1px solid;">' + i + '</a>';
}
}
}
Html += '<a href="javaScript:void(0)" class="nextPage">下一页</a>';
Html += '共有' + total + '条数据';
Html += '</p>';
$(pageEle).html(Html);
$(pageEle).find('select').val(index);
//上一页
$(pageEle).find('a[class=prePage]').bind('click',
function() {
var index = $(this).parent().parent().attr('index') - 0;
if (index > 1) {
$(this).parent().parent().attr('index', index - 1);
cndt.index = cndt.index - 1;
obj(url, cndt, dataEle, pageEle, ishow);
} else {
alert('还想去哪儿啊,这是第一页~');
}
});
//下一页
$(pageEle).find('a[class=nextPage]').bind('click',
function() {
var index = $(this).parent().parent().attr('index') - 0;
if (index < count) {
$(this).parent().parent().attr('index', index + 1);
cndt.index = (cndt.index - 0) + 1;
obj(url, cndt, dataEle, pageEle, ishow);
} else {
alert('别翻了,后面没有了~');
}
});
//当前页
$(pageEle).find('a[class=nowPage]').bind('click',
function() {
var index = $(this).parent().parent().attr('index') - 0;
$(this).parent().parent().attr('index', $(this).text());
cndt.index = $(this).text();
obj(url, cndt, dataEle, pageEle, ishow);
});
//指定页转跳
$(pageEle).find('select[class=nowPage]').bind('change',
function() {
console.log(11111111111);
var index = $(this).parent().parent().attr('index') - 0;
$(this).parent().parent().attr('index', $(this).val());
cndt.index = $(this).val();
obj(url, cndt, dataEle, pageEle, ishow);
});
}
来源: http://www.cnblogs.com/muchengqingxin/p/7428599.html