js 获取url参数

2021-01-21 00:13

阅读:471

标签:==   http   efi   lse   cat   dmi   fine   log   eof   

 1 //  示例urlStr:http://html/index.html?user=admin&pwd=123456
 2 
 3 function getRequest(urlStr) {
 4     if (typeof urlStr == "undefined") {
 5         var url = decodeURI(location.search); //获取url中"?"符后的字符串
 6     } else {
 7         var url = "?" + urlStr.split("?")[1];
 8     }
 9     var obj = new Object();
10     if (url.indexOf("?") != -1) {
11         var str = url.substr(1);
12         strs = str.split("&");
13         for (var i = 0; i ) {
14             obj[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
15         }
16     }
17     return obj;
18 }
19 
20 var params = getRequest();
21 console.log(params); //{"user":"admin","pwd":"123456"}

 

js 获取url参数

标签:==   http   efi   lse   cat   dmi   fine   log   eof   

原文地址:https://www.cnblogs.com/Blogzlj/p/13300261.html


评论


亲,登录后才可以留言!