Skip to content

Instantly share code, notes, and snippets.

@JagoWang
Created July 10, 2015 01:56
Show Gist options
  • Save JagoWang/6542c8007f7c58e1bc44 to your computer and use it in GitHub Desktop.
Save JagoWang/6542c8007f7c58e1bc44 to your computer and use it in GitHub Desktop.
JS获取请求参数数组及指定参数
//获取请求参数数组
function getUrlVars(){
var vars = [], hash;
var hashes = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
for(var i = 0; i < hashes.length; i++)
{
hash = hashes[i].split('=');
vars.push(hash[0]);
vars[hash[0]] = hash[1];
}
return vars;
}
//获取指定参数的value
function getUrlVar(name){
return getUrlVars()[name];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment