89203856 2015-07-09
//jquery页码控件
// 创建一个闭包
(function($) {
// 插件的定义
$.fn.pageTool = function(options) {
var totalPage = Math.ceil(total/pageSize);
var htmlStr = [];
htmlStr.push('...');
$('#kkpager').html(htmlStr.join(''));
//首页
$('#frist_page').click(function(){
$(this).pageTool({
total: total,
pageSize: pageSize,
curPage: 1,
showNum: showNum,
callback: function(curPage) {
}
});
});
//上一页
$('#back_page').click(function(){
$(this).pageTool({
total: total,
pageSize: pageSize,
curPage: curPage-1,
showNum: showNum,
callback: function(curPage) {
}
});
});
//绑定页码事件
$('.pageNum').click(function(){
$(this).pageTool({
total: total,
pageSize: pageSize,
curPage: parseInt($(this).text()),
showNum: showNum,
callback: function(curPage) {
}
});
});
//下一页
$('#next_page').click(function(){
$(this).pageTool({
total: total,
pageSize: pageSize,
curPage: ((curPage+1)>totalPage)?(totalPage):(curPage+1),
showNum: showNum,
callback: function(curPage) {
}
});
});
//最后一页
$('#last_page').click(function(){
$(this).pageTool({
total: total,
pageSize: pageSize,
curPage: totalPage,
showNum: showNum,
callback: function(curPage) {
}
});
});
//跳转页面绑定事件
$('#kkpager_btn_go').click(function(){
if(checkRate(total, pageSize)){
$(this).pageTool({
total: total,
pageSize: pageSize,
curPage: parseInt($('#kkpager_btn_go_input').val(),10),
showNum: showNum,
callback: function(curPage) {
}
});
}
});
//调整每页显示多少条数据
$('#max_item').change(function(){
$(this).pageTool({
total: total,
pageSize: parseInt($('#max_item').val(),10),
curPage: 1,
showNum: showNum,
callback: function(curPage) {
}
});
});
};
//判断奇偶
function chk(num){
return (num%2 == 0)?1:0;
}
//判断是不是整数
function checkRate(total, pageSize) {
var curPage = $('#kkpager_btn_go_input').val();
var re = /^[1-9]+[0-9]*]*$/;
if (notEmptys(curPage)){
if (!re.test(curPage)) {
alert("请输入正整数");
return false;
}else{
if(curPage <= Math.ceil(total/pageSize)){
return true;
}else{
alert("请输入正确的页码");
return false;
}
}
}
}
// 定义暴露format函数
$.fn.pageTool.fristPage = function() {
};
$.fn.pageTool.defaults = {
"total": 0,
"curPage": 1,
"pageSize": 10,
"showNum": 7,
"changeColor": true,
"changeMaxItem": true,
"goToOtherPage": true
};
// 闭包结束
})(jQuery);
//调用 $(function(){ $('#kkpager').pageTool({ total: 180, pageSize: 10, curPage: 1, showNum: 7, changeColor: true, changeMaxItem: true, goToOtherPage: true, callback: function(curPage) { } }); });