Created
February 17, 2016 09:42
-
-
Save mcattx/7ead9a5f663ff0910ff5 to your computer and use it in GitHub Desktop.
分割页面url,获取对应的参数值。
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
| /** | |
| * 分割页面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