This article describes how to query string parameters in javascript. The example shows how to use javascript to obtain the corresponding parameters in a URL, for more information about how to query string parameters in javascript, see the following example. Share it with you for your reference. The specific implementation method is as follows:
The code is as follows:
/* Parse the query string and return an object containing all parameters */
Function getQueryStringArgs (){
// Obtain the query string and remove the question mark at the beginning
Var qs = (location. search. length> 0? Location. search. substring (1 ):'');
// The object that saves the data
Args = {};
// Obtain each item
Var items = qs. length? Qs. split ('&'): [],
Item = null,
Name = null,
// Used in the 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;
}
In this way, you can easily obtain the corresponding parameter values in the URL.
I hope this article will help you design javascript programs.