This article describes the method of querying string parameters by javascript. Share it for your reference. The specific implementation method is as follows:
Copy the code as follows:/* Parsing the query string returns an object containing all parameters*/
function getQueryStringArgs(){
//Get the query string and remove the beginning question mark
var qs = (location.search.length > 0 ? location.search.substring(1): '');
//The object that saves the data
args = {};
//Get each item
var items = qs.length ? qs.split('&') : [],
item = null,
name = null,
//Use in for loop
i = 0, len = items.length;
//Add each item to the args object one by one
for(i = 0 ; i < len; i++){
item = items[i].split('=');
name = decodeURIComponent(item[0]);
value = decodeURIComponent(item[1]);
if(name.length){
args[name] = value;
}
}
return args;
}
This way, you can easily get the corresponding parameter values in the URL.
I hope this article will be helpful to everyone's JavaScript programming.