根据http://hi.baidu.com/fenggandeguozi/blog/item/d8f4ad009fb79f0f1c95835c.html的js前台分页代码,修改一下,加入首页 ,上页,下页,末页的功能。
//页面跳转
function ready2go(){
var obj=this;
$("#"+obj.page_obj_id+" a").live("click",function(){ //点击页码的时候跳到相应页
alert("obj.cpage:"+obj.cpage);
var tmp = $(this).attr("p");
if(isNaN(tmp)&&tmp=="next"){
if((obj.cpage+1)>obj.totalpage){
obj.target_p=obj.totalpage
}else{
obj.target_p=obj.cpage+1;
}
}else if(isNaN(tmp)&&tmp=="prev"){
if((obj.cpage-1)==0){
obj.target_p=1
}else{
obj.target_p=obj.cpage-1;
}
}else{
obj.target_p=parseInt($(this).attr("p"));
}
gotopage.call(obj,obj.target_p);
})
}
//生成跳转链接
jsPage.prototype.page=function(){
//alert(this.totalpage);
if(this.totalpage<=10){ //总页数小于十页 页码以十页为单位
for (this.count=1;this.count<=this.totalpage;this.count++) {
if(this.count!=this.cpage) {
if(this.count==1){
this.outstr = this.outstr + "<a href='javascript:void(0)' p='"+this.count+"' >"+"首页"+"</a>";
this.outstr = this.outstr + "<a href='javascript:void(0)' p='next' >"+"下页"+"</a>";
this.outstr = this.outstr + "<a href='javascript:void(0)' p='prev' >"+"上页"+"</a>";
}else{
if(this.count==this.totalpage){
this.outstr = this.outstr + "<a href='javascript:void(0)' p='"+this.count+"' >"+"末页"+"</a>";
}else{
this.outstr = this.outstr + "<a href='javascript:void(0)' p='"+this.count+"' >"+this.count+"</a>";
}
}
}else{
//alert(this.outstr);
if(this.count==1){
this.outstr = this.outstr + "<span class='current' >"+"首页"+"</span>";
this.outstr = this.outstr + "<a href='javascript:void(0)' p='next' >"+"下页"+"</a>";
this.outstr = this.outstr + "<a href='javascript:void(0)' p='prev' >"+"上页"+"</a>";
}else{
if(this.count==this.totalpage){
this.outstr = this.outstr + "<span class='current' >"+"末页"+"</span>";
}else{
this.outstr = this.outstr + "<span class='current' >"+this.count+"</span>";
}
}
}
}
}