posts - 7,  comments - 58,  trackbacks - 0

          我的評論

          function $el(el) {
          return document.createElement(el);
          }
          function $ap(p, n) {
          p = p || document;
          p.appendChild(n);
          }
          function $id(_id) {
          return document.getElementById(_id);
          }
          (function(){
          var _style = $el("link");
          _style.href = "jpage.css";
          _style.rel = "stylesheet";
          _style.type = "text/css";
          document.getElementsByTagName("HEAD").item(0).appendChild(_style);

          })();

          /**
          * fun: 實現(xiàn)ajax分頁效果
          * 參數(shù)說明:c 分頁控件顯示的容器ID,一般用DIV的ID
          * recordCount: 總記錄數(shù)
          * service 請求分頁數(shù)據(jù)的js方法指針,分頁控件負責回調(diào), 原型 function fun(curPage, pageSize) {....}
          */
          function JPage(c, recordCount, service, pageSize, group) {
          this._c = $id(c);
          this.pageSize = pageSize || 10; //一頁幾條
          this.pageCount = (recordCount % this.pageSize) == 0? (recordCount / this.pageSize): parseInt((recordCount / this.pageSize) + 1); //總頁數(shù)
          this.service = service; //回調(diào)方法
          this.group = group || 11; //一組幾頁
          this.pageData = new Array(this.group); //當前要顯示的頁對象索引緩存區(qū)
          this.curPage = 1; // 初始化為第一頁為當前頁
          var that = this;
          this.pageEvt = function(thePg) {
          this.curPage = thePg;
          this.service(this.curPage, this.pageSize);
          this.render();
          };
          this.render = function() {
          this._c.innerHTML = "";
          if(recordCount == 0) return;
          this.createFirstPage();
          this.readData(); //準備分頁索引
          this.createPrePage();
          this.createPages();
          this.createNextPage();
          this.createEndPage();
          };
          this.createEndPage = function() {
          var _span = $el("span");
          var epg = new FEPg(this, this.pageCount, "EndCssClass"); //最后一頁
          $ap(_span, epg.getView());
          $ap(this._c, _span);
          };
          this.createFirstPage = function() {
          var _span = $el("span");
          var fpg = new FEPg(this, 1, "FirstCssClass"); //首頁
          $ap(_span, fpg.getView());
          $ap(this._c, _span);
          };
          this.createPages = function() {
          for(var n = 0; n < this.group; n++) {
          if(this.pageData[n] == -2) break; //
          var _span = $el("span");
          var _page = new Pg(this, this.pageData[n]);
          $ap(_span, _page.getView());
          $ap(this._c, _span);
          }
          };
          this.createPrePage = function() {
          var preSpan = $el("span");
          var prePage = new PrePg(this, this.curPage - 1);
          $ap(preSpan, prePage.getView());
          $ap(this._c, preSpan);
          };
          this.createNextPage = function() {
          var nextSpan = $el("span");
          var nextPage = new NextPg(this, this.curPage + 1);
          $ap(nextSpan, nextPage.getView());
          $ap(this._c, nextSpan);
          };
          this.readData = function() {
          for(var i = 0; i < this.group; i++) this.pageData[i] = -2;
          var firstIndex = (this.pageCount <= this.group || this.curPage <= parseInt(this.group / 2))? 1: this.curPage - parseInt(this.group / 2);
          if(firstIndex > this.pageCount) return;
          this.pageData[0] = firstIndex;
          for(var n = 1; n < this.group; n++) {
          if(this.pageData[n-1] >= this.pageCount) break;
          this.pageData[n] = this.pageData[n-1] + 1;
          }
          };
          this.render();
          }

          /**
          * fun: 頁模型基類
          * 參數(shù)說明:owner分頁對象,the 當前頁索引, pre 上一頁索引, _next 下一頁索引, vtxt 顯示文本(用于“上一頁”及“下一頁”)
          */
          function Pg(owner, the, vtxt) {
          this._owner = owner;
          this._self = the;
          this._vtxt = vtxt || the;
          this._view = $el("a");
          this._view.innerHTML = this._vtxt;
          var that = this;
          this.getView = function() {
          if(this._self == this._owner.curPage) {this._view.className = "activePage"; return this._view; }
          this._view.href = "javascript:;";
          this._view.onclick = function() {
          that._owner.pageEvt(that._self); //回傳點中的頁對象頁索引
          }
          return this._view;
          };

          this.getMe = function() {
          return this._self;
          };

          }

          /**
          * fun: Pg子類"上一頁“類模型
          */
          function PrePg(owner, the, vtxt) {
          this._super = Pg;
          this._super(owner, the, " "); //當前頁為第一頁時,the為0
          var that = this;

          this.getView = function() {
          if(this._self == 0) { this._view.className = "NoView"; return this._view; } //如果當前頁為第一頁,不創(chuàng)建上一頁對象視圖
          this._view.href = "javascript:;";
          this._view.onclick = function() {
          that._owner.pageEvt(that._self); //回傳點中的頁對象頁索引
          }
          this._view.className = "PreCssClass";
          return this._view;
          };

          }

          /**
          * fun: Pg子類"下一頁”類模型
          */
          function NextPg(owner, the, vtxt) {
          this._super = Pg;
          this._super(owner, the, " ");
          var that = this;

          this.getView = function() {
          if(this._self == this._owner.pageCount + 1) { this._view.className = "NoView"; return this._view; } //如果當前頁為第一頁,不創(chuàng)建上一頁對象視圖
          this._view.href = "javascript:;";
          this._view.onclick = function() {
          that._owner.pageEvt(that._self); //回傳點中的頁對象頁索引
          }
          this._view.className = "NextCssClass";
          return this._view;
          };
          }

          /**
          * fun: 第一頁及最后一頁類模型
          */
          function FEPg(owner, the, _class) {
          this._super = Pg;
          this._super(owner, the, " ");
          var that = this;
          this.getView = function() {
          if(this._owner.pageCount == 0) { return this._view; } //如果當前頁為第一頁,不創(chuàng)建上一頁對象視圖
          this._view.href = "javascript:;";
          this._view.onclick = function() {
          that._owner.pageEvt(that._self); //回傳點中的頁對象頁索引
          }
          this._view.className = _class;
          return this._view;
          }
          }
          <2025年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿(3)

          隨筆分類

          隨筆檔案

          文章分類

          相冊

          收藏夾

          博客好友

          搜索

          •  

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 封丘县| 巍山| 静乐县| 茌平县| 方正县| 囊谦县| 清流县| 黄大仙区| 锦屏县| 宁夏| 贵港市| 舟曲县| 松桃| 通渭县| 凤山市| 华蓥市| 尼玛县| 西充县| 鲁山县| 临江市| 思茅市| 盱眙县| 轮台县| 汝阳县| 屯留县| 新乡县| 湾仔区| 巨野县| 林周县| 望江县| 鹤庆县| 柏乡县| 垫江县| 中超| 新巴尔虎左旗| 朝阳区| 基隆市| 湟源县| 通渭县| 堆龙德庆县| 中西区|