Skip to content

Instantly share code, notes, and snippets.

@yantze
Created June 30, 2015 10:22
Show Gist options
  • Save yantze/2088814e1f93ef5d9560 to your computer and use it in GitHub Desktop.
Save yantze/2088814e1f93ef5d9560 to your computer and use it in GitHub Desktop.
解析类似URI query字符串,返回数组对象
/**
* 解析类似URI query字符串,返回数组对象
* @param uri 类似location.search
* @param key 数组的key name
* @returns {*}
*/
function parse_param(uri, key)
{
var regex = /[?&]([^=#]+)=([^&#]*)/g,
url = uri,
match;
while(match = regex.exec(url)) {
if (match[1] == key)
return match[2];
}
return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment