Home > Web Front-end > JS Tutorial > JS request function is used to obtain url parameters_javascript skills

JS request function is used to obtain url parameters_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 18:27:04
Original
1978 people have browsed it
Copy code The code is as follows:

function request(strParame) {
var args = new Object( );
var query = location.search.substring(1);

var pairs = query.split("&"); // Break at ampersand
for(var i = 0; i < pairs.length; i ) {
var pos = pairs[i].indexOf('=');
if (pos == -1) continue;
var argname = pairs[i ].substring(0,pos);
var value = pairs[i].substring(pos 1);
value = decodeURIComponent(value);
args[argname] = value;
}
return args[strParame];
}

For example, if you want to get aaa.aspx?id=2

The usage method is: var id= request('id ');

The following are some article references compiled by Script House
JS extension examples for obtaining url parameters
jQuery plug-in for obtaining URL parameters
Garbled characters caused by JS URL passing Chinese parameters
Related labels:
js
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
Where is js written?
From 1970-01-01 08:00:00
0
0
0
js file code not found
From 1970-01-01 08:00:00
0
0
0
js addClass not working
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template