js中的OO

 以前,写js函数,很少考虑oo的概念。前段时间做一个引导页,引导页格式比较固定,每页只显示三块,由于引导页在igw和ibw中都要引用,对大小位置要求比较苛刻,因此,我放弃了通过隐藏html元素来达到分页的效果。我采用弄好框架,改变innerHTML属性来达到分页的效果。由于每块都有个左图标,标题,又图标这四个元素,因此,我用js构造了下面的类:

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;
               }
  

 

 

       呵呵,当时感觉还不错,这会感觉很乱。 

转载于:https://www.cnblogs.com/xinlingjingtu/archive/2009/01/14/1375278.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值