Copy codeThe Code is as follows:
Function searchParse (){
Var resultObj = {};
Var search = window. location. search;
If (search & search. length> 1 ){
Var search = search. substring (1 );
Var items = search. split ('&');
For (var index = 0; index <items. length; index ++ ){
If (! Items [index]) {
Continue;
}
Var kv = items [index]. split ('= ');
ResultObj [kv [0] = typeof kv [1] === "undefined "? "": Kv [1];
}
}
Return resultObj;
}
// Sample Code
// Url: http: // localhost/default. aspx? A = hello & B = kt & c = group
Var searchObj = searchParse ();
Var a = searchObj ["a"]; // a = hello
Var B = searchObj ["B"]; // B = kt
Var c = searchObj ["c"]; // c = group
If the above Code is not good enough, you can refer to the following article.
Obtain url parameter function code from url parameters and script tags in javascript
The JavaScript URL parameter is read from the simplified version.
Javascript [js] Code for obtaining url parameters