方法一:
例如:得到的url
var url = window.location.href; var querys = url.substring(url.indexOf('?') + 1).split('&'); var result=[]; for(var i=0;i<querys.length;i++){ var temp=querys[i].split('='); if(temp.length<2){ result[temp[0]]=''; } else{ result[temp[0]]=temp[1]; } } console.log(result);
result返回[ id:3]
方法二:
var code = ""; function GetRequest() { var url = location.search; if (url.indexOf("?") != -1) { //是否有参数 var str = url.substr(1); strs = str.split("="); //alert(strs[1]); code = strs[1]; } } GetRequest(); console.log(code);
标签:code,url,GetRequest,JS,strs,var,参数值 From: https://www.cnblogs.com/lgx5/p/17594249.html