Created
June 30, 2015 10:22
-
-
Save yantze/2088814e1f93ef5d9560 to your computer and use it in GitHub Desktop.
解析类似URI query字符串,返回数组对象
This file contains 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
/** | |
* 解析类似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