js取url问号后的参数方法封装

话不多说直接上代码:

<script type="text/javascript">
function GetRequest() { 
   var url = location.search; //获取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; 
} 
var s=GetRequest();
console.log(s)
</script>

 

js取url问号后的参数方法封装

上一篇:http网络协议包


下一篇:npm install 时总是报phantomjs-prebuilt@2.1.16安装失败