现在的位置: 首页 > 综合 > 正文

JS动态创建连接地址(通用分页)

2013年01月30日 ⁄ 综合 ⁄ 共 3526字 ⁄ 字号 评论关闭

var q = null;/****全局控制成员*****/

function Count() {
                this.canada = 1;
                this.less = 1;
                this.setCanada = function (canada) {
                        this.canada = canada + 1;
               };
               this.getCanada = function () {
                        return this.canada;
               };
               this.setLess = function (less) {
                        if (less > 1) {
                              this.less = less - 1;
                        } else {
                              this.less = 1;
                        }
              };
              this.getLess = function () {
                       return this.less;
              };
}

 

function processNextPage(currentPage) {
              var count = new Count();
              count.setCanada(currentPage);
              if (q.getTag() != "") {
                              var tempStr = "";
                              for (var i = 1; i < q.getKeyValue().length; i++) {
                                           tempStr += "&" + q.getKeyValue()[i];
                              }
                             document.forms[0].action = q.getActionName() + q.getPage() + count.getCanada() + tempStr;
              } else {
                             document.forms[0].action = q.getActionName() + "?page=" + count.getCanada();
             }
            document.forms[0].submit();
}

 

function processFrontPage(currentPage) {
            var count = new Count();
            count.setLess(currentPage);
            if (q.getTag() != "") {
                             var tempStr = "";
                             for (var i = 1; i < q.getKeyValue().length; i++) {
                                          tempStr += "&" + q.getKeyValue()[i];
                            }
                           document.forms[0].action = q.getActionName() + q.getPage() + count.getLess() + tempStr;
            } else {
                           document.forms[0].action = q.getActionName() + "?page=" + count.getLess();
            }
           document.forms[0].submit();
}

 

function urlInit() {
           var path = window.location.pathname;
           var action = path.substring(path.lastIndexOf("/") + 1);
           var searchPath = window.location.search;
           var page = searchPath.substring(0, 6);
           var tempStr = searchPath.substring(searchPath.indexOf("&"));
           var keyValue = tempStr.split("&");
           q = new query();
           q.setActionName(action);
           q.setTag(searchPath);
           q.setPage(page);
           q.setKeyValue(keyValue);
}

 

function query() {
           this.actionName = null;
           this.tag = null;
           this.page = null;
           this.key = null;
           this.keyValue = null;
           this.setActionName = function (action) {
                            this.actionName = action;
           };
           this.getActionName = function () {
                            return this.actionName;
           };
           this.setTag = function (tagObject) {
                            this.tag = tagObject;
           };
           this.getTag = function () {
                            return this.tag;
           };
           this.setPage = function (page) {
                            this.page = page;
           };
           this.getPage = function () {
                            return this.page;
           };
           this.setKey = function (key) {
                            this.key = key;
           };
           this.getKey = function () {
                            return this.key;
           };
           this.setKeyValue = function (keyValue) {
                            this.keyValue = keyValue;
           };
           this.getKeyValue = function () {
                            return this.keyValue;
           };
}

window.attachEvent("onload", urlInit);/****为对象的事件绑定触发对象*****/

 

抱歉!评论已关闭.