Created
July 10, 2015 01:56
-
-
Save JagoWang/6542c8007f7c58e1bc44 to your computer and use it in GitHub Desktop.
JS获取请求参数数组及指定参数
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//获取请求参数数组 | |
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