zoukankan      html  css  js  c++  java
  • 将url的查询参数解析成字典对象

    方法一:

    function getQueryObject(url) {
        url = url == null ? window.location.href : url;
        var search = url.substring(url.lastIndexOf("?") + 1);
        var obj = {};
        var reg = /([^?&=]+)=([^?&=]*)/g;
        search.replace(reg, function (rs, $1, $2) {
            var name = decodeURIComponent($1);
            var val = decodeURIComponent($2);               
            val = String(val);
            obj[name] = val;
            return rs;
        });
        return obj;
    }
     
    getQueryObject("http://www.w3school.com.cn/tiy/t.asp?f=js_library_jquery");
    
    
    //Object {f: "js_library_jquery"}
    

    方法二:

    function GetRequest(url) { 
        url = url == null ? window.location.href : url;//获取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]]=unescape(strs[i].split("=")[1]); 
            } 
        } 
        return theRequest; 
    } 
    
    GetRequest("http://www.w3school.com.cn/tiy/t.asp?f=js_library_jquery");
    
    
    //Object {ttp://www.w3school.com.cn/tiy/t.asp?f: "js_library_jquery"}
    
  • 相关阅读:
    vue ssr
    webpack-dev-server proxy代理
    PHP连数据库生成数据字典
    redis.rpm 安装
    centos 6.5安装NodeJS
    Jenkins + git + maven 安装
    最新版本GIT安装
    身份证校验
    快递100物流公司列表
    redis 安装
  • 原文地址:https://www.cnblogs.com/xjuan/p/5502534.html
Copyright © 2011-2022 走看看