JavaScript获取地址栏中的参数值并存入一个对象

 1 var getArgs = function () 
 2 { 
 3     var args = new Object(); //声明一个空对象 
 4     var query = window.location.search.substring(1); // 取查询字符串
 5     var pairs = query.split("&"); // 以 & 符分开成数组 
 6     for(var i = 0; i < pairs.length; i++) { 
 7         var pos = pairs[i].indexOf('='); // 查找 "name=value" 对 
 8         if (pos == -1) continue; // 若不成对,则跳出循环继续下一对 
 9         var argname = pairs[i].substring(0,pos); // 取参数名 
10         var value = pairs[i].substring(pos+1); // 取参数值 
11         value = decodeURIComponent(value); // 若需要,则解码 
12         args[argname] = value; // 存成对象的一个属性 
13     } 
14     return args; // 返回此对象 
15 }
原文地址:https://www.cnblogs.com/shanligang/p/3902906.html