• 获取地址栏参数


    /* *****************************
    * 获取参数值
    * @param name 参数名称
    * @returns 参数值
    ***************************** */
     
    CloudShareCommon.prototype.getQueryString = function (name) {
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
        var r = window.location.search.substr(1).match(reg);
        var context = "";
        if (r != null)
            context = r[2];
        reg = null;
        r = null;
        return context == null || context == "" || context == "undefined" ? "" : context;
    };    
     
    --------------------------------------------------------------------------------------------------------------------
    //获取URL参数
    function getQueryString(name) {
        var url = window.location.search; //获取url中"?"符后的字串
        var theRequest = new Object();
        if (url.indexOf("?") != -1) {
            var str = url.substr(1);
            strs = str.split("&");
            for (var i = 0; i < strs.length; i++) {
                theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
            }
        }
    return theRequest[name];
    }    
     
    --------------------------------------------------------------------------------------------------------------------
    var a="https://www.baidu.com?user_id=324300147&mobile=15802038598"
    
    function parseQueryString(url) {
        var json = {};
        var arr = url.substr(url.indexOf('?') + 1).split('&');
        arr.forEach(function(item) {
            var tmp = item.split('=');
            json[tmp[0]] = tmp[1];
        })
        return json;
    }
    
    alert(parseQueryString(a).mobile);
  • 相关阅读:
    基于蓝牙的安卓客户端开发
    在word文档中添加上角标和下角标
    vs2008打开类视图,看不到类的解决方法
    容器vector 迭代器iterator 应用
    next_permutation()
    pair运用
    vector学习
    容器之vector
    指针 * &
    派生类中的构造函数和析构函数
  • 原文地址:https://www.cnblogs.com/queende7/p/8668892.html
Copyright © 2020-2023  润新知