Skip to content

Instantly share code, notes, and snippets.

@jikeytang
Last active August 29, 2015 14:03
Show Gist options
  • Save jikeytang/87cd4a111e70e231c416 to your computer and use it in GitHub Desktop.
Save jikeytang/87cd4a111e70e231c416 to your computer and use it in GitHub Desktop.
[ Javascript ] - 20140630-题目1
如何获取URL地址栏参数?
如:https://gist.github.com/send.php?name=jikey&age=30&lan=js;
getParam(); -> { name : jikey, age : 30, lan : js}
getParam('name') -> jikey
PS:
1. 回复时注意加上下面这句话,才会有语法高亮或格式缩进。
```javascript
// you code
```
2. 粘贴代码时请使用shift+tab,缩进前面的空白。
@zhishaofei3
Copy link

function getUrlParam(key) {
    var match, args = {},
        reg = /(?:([^&]+)=([^&]+))/g;
    while (match = reg.exec(decodeURIComponent(location.search.substring(1)))) {
        args[match[1]] = match[2];
    }
    return key ? args[key] : args;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment