//公共分页工具条
///[dataEle]数据主体
//[ele]分页主体
///[obj]被传入的类
//[where]条件
///[w]按照何种方式搜索
function PagerTool(dataEle, ele, obj, tag1, tag2, where) {
var total = $(ele).attr( 'total' ) - 0;
var rowcount = $(ele).attr( 'rowcount' ) - 0;
var index = $(ele).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>' ;
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 += '</p>' ;
$(ele).html( '' ).html(Html);
//上一页
$(ele).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);
obj.Pager(dataEle, ele, tag1, tag2, index - 1, where);
}
});
//下一页
$(ele).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);
obj.Pager(dataEle, ele, tag1, tag2, index + 1, where);
}
});
//当前页
$(ele).find( 'a[class=nowPage]' ).bind( 'click' , function () {
var index = $( this ).parent().parent().attr( 'index' ) - 0;
$( this ).parent().parent().attr( 'index' , $( this ).text());
obj.Pager(dataEle, ele, tag1, tag2, $( this ).text(), where);
});
}
|