URLのアスタリスク({)のパラメータを取得して設定します。

1535 ワード

例:http://gzmsg.com/go/news.aspx#page=12
var DF = {};
(function () {
    var a = function () {
        var d, e = {},
		b;
        d = window.location.hash.replace(/^#/, "");
        if (d == "") {
            this.uhash = {}
        } else {
            d = d.split("|");
            for (var c = 0; c < d.length; c++) {
                b = d[c].split("=");
                e[b[0]] = b[1]
            }
            this.uhash = e
        }
    };
    a.prototype.set = function (e) {
        var d = [];
        if (arguments.length == 1 && /Object/.test(Object.prototype.toString.call(e))) {
            for (var c in e) {
                if (e.hasOwnProperty(c)) {
                    this.uhash[c] = e[c]
                }
            }
            for (var b in this.uhash) {
                d.push(b + "=" + this.uhash[b])
            }
            window.location.hash = d.join("|")
        } else {
            logger.info("  hash      ")
        }
    };
    a.prototype.get = function (b) {
        if (arguments.length == 1) {
            return this.uhash[b]
        } else {
            return this.uhash
        }
    };
    DF.URLHash = new a()
})();
設定:var a=DF.URLHash.get(「page」);
取得:var b=DF.URLHash.set(「page」);