javascript分页代码实例共享(js分页)

呼叫:

复制代码代码如下所示:
VaR的网页更新预测的数据模型=函数(指数){
VaR的HTML =寻呼机(分
}


实现uff1a

复制代码代码如下所示:
寻呼机=功能(divpager,页索引,大小测度,网页更新预测的数据模型,选择){

无功theopt = { {
BarSize:5、显示页面/页面数
BarTemplate:{酒吧} { } { } {去测度totalpage }页面 / /显示模板
自动隐藏:真的, / /自动隐藏
showfirst: / /真totalpage > barsize时不会自动显示第一页链接
showlast: / /真totalpage > barsize时不会自动显示上一页链接
showgoto: / /去真实,是否显示
AutoHideGoTo:真 / /如果太少的自动隐藏到
};

如果(选择){
如果(选择。barsize)
theopt.barsize = opt.barsize;
如果(选择。bartemplate)
theopt.bartemplate = opt.bartemplate;
如果(opt.autohide = false)
theopt.autohide = false;
如果(opt.showfirst = false)
theopt.showfirst = false;
如果(opt.showlast = false)
theopt.showlast = false;
如果(opt.showgoto = false)
theopt.showgoto = false;
如果(opt.autohidegoto = false)
theopt.autohidegoto = false;
}
var = window.mypagerchanges =处理(函数(x){ return x;}(window.mypagerchanges | | { }));

如果(!mypagerchanges { divpager }){ } = mypagerchanges divpager网页更新预测的数据模型;

VaR的起始= 0; / /条起始页
VaR的末页= 0; / /条结束页
无功showfirst =真;
无功showlast =真;


如果(isnan(PageIndex)){
页索引= 1;
}
页索引= parseInt(页索引);
如果(页索引0)
页索引= 1;
如果(PageIndex * PageSize >测度){
math.ceil PageIndex =(测度 / PageSize);
}

如果(测度= = 0){ / /如果没有数据
document.getelementbyid(divpager).innerHTML = ;
返回;
}

totalpage = math.ceil(VaR测度 / PageSize);
如果(theopt.autohide测度<= PageSize){ / /自动隐藏
document.getelementbyid(divpager).innerHTML = ;
返回;
}

如果(totalpage theopt。barsize){
起始页= 1;
this.totalpage末页=;
theopt.showlast = theopt.showfirst = false;
}
{其他
如果(PageIndex <= math.ceil(theopt.barsize / 2)){ / /大多数网页时
起始页= 1;
theopt.barsize末页=;
theopt.showfirst = false;
}
如果(页索引>(totalpage - theopt.barsize / 2)){ / /的最后几页
起始= totalpage - theopt.barsize + 1;
totalpage末页=;
theopt.showlast = false;
}
否则{中间页
起始=页索引- Math.ceil(theopt.barsize / 2)+ 1;
末页= PageIndex + math.floor(theopt.barsize / 2);
}
如果(totalpage <=(theopt.barsize×1.5)){
theopt.showlast = theopt.showfirst = false;
}
}

功能_getlink(指数、TXT){
如果(!txt)索引;
返回+;
}

var =barhtml ; / /条
barhtml = PageIndex = = 1 :(_getlink页索引1,页上的);
如果(theopt。showfirst){
barhtml = _getlink(1 +)…;
}
对于(VAR指标=起始;指数<末页;指数+ +){

如果(指数= = PageIndex){
barhtml +指数+ + = ;
}
{其他
barhtml = _getlink(指数);
}
}
如果(theopt。showlast){
barhtml = …+ _getlink(totalpage);
}
barhtml = PageIndex = =totalpage :_getlink(PageIndex + 1,下一页);

无功gotohtml = ; / /去框和按钮
如果(theopt.showgoto theopt.bartemplate.indexof({去})> 0){
如果((theopt.autohidegoto,totalpage > 15)| | theopt.autohidegoto = = false){
无功txtid = divpager +_goindex ;
无功indexval =document.getelementbyid(+ txtid + )的价值。;
= gotohtml ;
= gotohtml ;
}
}

替换模板
无功pagerhtml = theopt.bartemplate.replace({ } 酒吧
更换({ }测度
更换({ } 页索引
更换({ }totalpage
替换()

document.getelementbyid(divpager).innerHTML = pagerhtml;
返回pagerhtml;
};