zoukankan      html  css  js  c++  java
  • 获取和设置URL里星号(#)的参数

    示例: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");

  • 相关阅读:
    Unity小地图Map
    DoTween扩展Transform
    Android开发笔记1.2
    Android开发笔记1.1.1
    Unity向量夹角
    使用vi
    MIPS 两个数的和(输入,计算,输出)
    python openpyxl 读取excel表操作
    javaI/O文件,读操作
    试用git遇见问题
  • 原文地址:https://www.cnblogs.com/sntetwt/p/3337446.html
Copyright © 2011-2022 走看看