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

WBOY
WBOYOriginal
2016-05-16 18:27:041939browse
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
Statement:
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