Recently, when I was making a page, I needed to use JavaScript to get the url parameters. I found that there were so many things on the Internet, and there were so many errors. I was really confused and wasted a lot of time. So, I will summarize it and find a useful one. That’s it. Let me first state that it is simpler to use regular expressions, but the compatibility and speed of multiple browsers cannot be guaranteed, so I will use one that is compatible with multiple browsers
The most important thing is to use
function request(paras){
var url = location.href;
var paraString = url.substring(url.indexOf("?") 1,url.length).split("&" );
var paraObj = {}
for (i=0; j=paraString[i]; i ){
paraObj[j.substring(0,j.indexOf("=")). toLowerCase()] = j.substring(j.indexOf("=") 1,j.length);
}
var returnValue = paraObj[paras.toLowerCase()];
if(typeof( returnValue)=="undefined"){
return "";
}else{
return returnValue;
}
}
This function will be used in the future It’s convenient, you won’t have to look for it everywhere