1. 程式人生 > >url中的查詢字符串的參數解析

url中的查詢字符串的參數解析

substring ava nbsp UNC ring rgs component for循環 AR

 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>

url中的查詢字符串的參數解析