url中的查询字符串的参数解析

 1 <script>
 2     // 查询字符串函数location.search;"?q=javascript"
 3 
 4     function getQueryStringArgs(){
 5         //取得查询字符串并去掉开头的问号
 6         var qs=(location.search.length>0?location.search.substring(1):''),
 7         //保存数据对象;
 8         args={};
 9         //取得每一项
10         items=qs.length?qs.split('&'):[],
11             item=null,
12             name=null,
13             value=null,
14             //在for循环中使用
15         i=0,
16             len=item.length;
17         //逐个将每一项添加到args对象中、
18         for(i=0;i<len;i++){
19             item=items[i].split('=');//分割后得到的是数组
20             name=decodeURIComponent(item[0]);
21             value=decodeURIComponent(item[0]);
22             if(name.length){
23                 args[name]=value;
24             }
25         }
26         return args;
27     }
28 </script>


原文地址:https://www.cnblogs.com/yangguoe/p/9039156.html