因开发中使用较多,封装成了一个方法,返回一个json对象
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>url参数截取</title> </head> <body> <script type="text/javascript"> var url = ‘localhost:8080/h5/loan/detail?home=1&loanId=31652&showWindow=1‘; console.log(urlIntercept(url));
function urlIntercept(str){ var urlStr = str.substring(str.indexOf(‘?‘)+1,str.length); var strArr={}; // console.log(urlStr); urlStr = urlStr.split(‘&‘); for(var i = 0;i<urlStr.length;i++){ var parmas= urlStr[i].split(‘=‘); var key = parmas[0], value=parmas[1]; strArr[key]=value; } return strArr; }
</script> </body> </html>