function AppPanel(leftImg,rightImg,title,content)
{
this.leftImg=leftImg;
this.rightImg=rightImg;
this.title=title;
this.content=content;
}
对于所有的块,我定义了个全局数组来保存:
var arrApp = new Array();
然后写分页函数
function PageInfo(arrApp,pageSize,pageIndex)
{
this.BeginIndex=0;
this.EndIndex=0;
this.PageCnt=0;
this.initPageInfo=initPageInfo(arrApp,pageSize,pageIndex);
}
function initPageInfo(arrApp,pageSize,PageIndex)
{
if(typeof(arrApp)=="undefined") return false;
if(arrApp.length<1) return false;
if(pageSize<1||PageIndex<1) return false;
PageInfo.prototype.PageCnt=Math.ceil(arrApp.length/pageSize);
if(PageIndex>PageInfo.prototype.PageCnt) return false;
PageInfo.prototype.BeginInde = (PageIndex-1) * pageSize;
PageInfo.prototype.EndIndex= PageIndex * pageSize -1;
if(PageInfo.prototype.EndIndex>arrApp.length-1)
{
PageInfo.prototype.EndIndex=arrApp.length-1;
}
return true;
}
然后这样,就可以调用分页了:
var aa = new PageInfo(arrApp,3,curPage);
if(aa.initPageInfo)
{
var id=0;
for(var i= PageInfo.prototype.BeginInde;i<=PageInfo.prototype.EndIndex;i++)
{
id=id+1;
document.getElementById("leftImg"+id).innerHTML=arrApp[i].leftImg;
document.getElementById("title"+id).innerHTML=arrApp[i].title;
document.getElementById("rightImg"+id).innerHTML=arrApp[i].rightImg;
document.getElementById("content"+id).innerHTML=arrApp[i].content;
}
呵呵,当时感觉还不错,这会感觉很乱。