jquery pager 访问 java_用jquery.pager.js实现分页

/** jQuery pager plugin

* Version 1.0 (12/22/2008)

* @requires jQuery v1.2.6 or later

*

* Example at:http://jonpauldavies.github.com/JQuery/Pager/PagerDemo.html*

* Copyright (c) 2008-2009 Jon Paul Davies

* Dual licensed under the MIT and GPL licenses:

*http://www.opensource.org/licenses/mit-license.php*http://www.gnu.org/licenses/gpl.html*

* Read the related blog post and contact the author athttp://www.j-dee.com/2008/12/22/jquery-pager-plugin/*

* This version is far from perfect and doesn't manage it's own state, therefore contributions are more than welcome!

*

* Usage: .pager({ pagenumber: 1, pagecount: 15, buttonClickCallback: PagerClickTest });

*

* Where pagenumber is the visible page number

* pagecount is the total number of pages to display

* buttonClickCallback is the method to fire when a pager button is clicked.

*

* buttonClickCallback signiture is PagerClickTest = function(pageclickednumber)

* Where pageclickednumber is the number of the page clicked in the control.

*

* The included Pager.CSS file is a dependancy but can obviously tweaked to your wishes

* Tested in IE6 IE7 Firefox & Safari. Any browser strangeness, please report.*/(function($) {

$.fn.pager=function(options) {var opts =$.extend({}, $.fn.pager.defaults, options);return this.each(function() {//empty out the destination element and then render out the pager with the supplied options

$(this).empty().append(renderpager(parseInt(options.pagenumber), parseInt(options.pagecount), options.buttonClickCallback));//specify correct cursor activity

$('.pages li').mouseover(function() { document.body.style.cursor = "pointer"; }).mouseout(function() { document.body.style.cursor = "auto"; });

});

};//render and return the pager with the supplied options

function renderpager(pagenumber, pagecount, buttonClickCallback) {//setup $pager to hold render

var $pager = $('

$pager.append(renderButton('上一页', pagenumber, pagecount, buttonClickCallback));//pager currently only handles 10 viewable pages ( could be easily parameterized, maybe in next version ) so handle edge cases

var startPoint = 1;//var endPoint = 9;

var endPoint = 5;if (pagenumber > 4 && pagenumber

startPoint= pagenumber - 2;

endPoint= pagenumber + 2;

}if(pagenumber>pagecount-2&& pagenumber

startPoint= pagecount - 4;

endPoint=pagecount;

}if (endPoint >pagecount) {

startPoint= pagecount - 8;

endPoint=pagecount;

}if (startPoint < 1) {

startPoint= 1;

}//loop thru visible pages and render buttons

for (var page = startPoint; page <= endPoint; page++) {var currentButton = $('

' + (page) + '');

page== pagenumber ? currentButton.addClass('pgCurrent') : currentButton.click(function() { buttonClickCallback(this.firstChild.data); });

currentButton.appendTo($pager);

}//render in the next and last buttons before returning the whole rendered control back.//$pager.append(renderButton('next', pagenumber, pagecount, buttonClickCallback)).append(renderButton('last', pagenumber, pagecount, buttonClickCallback));

$pager.append(renderButton('下一页', pagenumber, pagecount, buttonClickCallback));return$pager;

}//renders and returns a 'specialized' button, ie 'next', 'previous' etc. rather than a page number button

function renderButton(buttonLabel, pagenumber, pagecount, buttonClickCallback) {var $Button = $('

' + buttonLabel + '');var destPage = 1;//work out destination page for required button type

switch(buttonLabel) {case "first":

destPage= 1;break;case "上一页":

destPage= pagenumber - 1;break;case "下一页":

destPage= pagenumber + 1;break;case "last":

destPage=pagecount;break;

}//disable and 'grey' out buttons if not needed.

if (buttonLabel == "first" || buttonLabel == "上一页") {

pagenumber<= 1 ? $Button.addClass('pgEmpty') : $Button.click(function() { buttonClickCallback(destPage); });

}else{

pagenumber>= pagecount ? $Button.addClass('pgEmpty') : $Button.click(function() { buttonClickCallback(destPage); });

}return$Button;

}//pager defaults. hardly worth bothering with in this case but used as placeholder for expansion in the next version

$.fn.pager.defaults ={

pagenumber:1,

pagecount:1};

})(jQuery);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值