URL参数解析获取

var url = ‘https://gitbook.cn/gitchat/geekbooks?tag=JavaScript&name=pwwu&age=24‘;
        var temp1 = url.split(‘?‘);
        var pram = temp1[1];
        var keyValue = pram.split(‘&‘);
        var obj = {};
        for (var i = 0; i<keyValue.length; i++){
            var item = keyValue[i].split(‘=‘);
            var key = item[0];
            var value = item[1];
            obj[key] = value;
        }
        console.log(url);
        console.log(temp1);    //  [‘https://gitbook.cn/gitchat/geekbooks‘,‘tag=JavaScript&name=pwwu&age=24‘]
        console.log(pram);     //  tag=JavaScript&name=pwwu&age=24
        console.log(keyValue); //  [‘tag=JavaScript‘,‘name=pwwu‘,‘age=24‘]
        console.log(obj);      //  {tag:‘JavaScript‘,name:‘pwwu‘,age:‘24‘}

  

URL参数解析获取

上一篇:在IIS上部署ASP.NET MVC程序时使用虚拟目录的问题


下一篇:ajaxSetup