Skip to content

Instantly share code, notes, and snippets.

@mcattx
Created February 17, 2016 09:42
Show Gist options
  • Select an option

  • Save mcattx/7ead9a5f663ff0910ff5 to your computer and use it in GitHub Desktop.

Select an option

Save mcattx/7ead9a5f663ff0910ff5 to your computer and use it in GitHub Desktop.
分割页面url,获取对应的参数值。
/**
* 分割页面url,获取对应的参数值。
* 比如分割 http://www.yy.com/search?q=123&sharefrom=wechat ,返回 Object {q: "123", sharefrom: "wechat"}
* @param null
* @return {object}
*/
function separate() {
var originUrl = window.location.search;
originUrl = originUrl.substr(1);
var resultObj = {};
if (originUrl === '') {
return resultObj;
}
var resultArr = originUrl.split('&');
for (var i = 0, length = resultArr.length; i < length; i++) {
var resultElem = resultArr[i];
var tempArr = resultElem.split('=');
resultObj[tempArr[0]] = tempArr[1];
}
return resultObj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment