Skip to content

Instantly share code, notes, and snippets.

@codcodog
Last active March 20, 2019 08:57
Show Gist options
  • Save codcodog/d2bbf0137eba9d45e82aaea97dbd8d73 to your computer and use it in GitHub Desktop.
Save codcodog/d2bbf0137eba9d45e82aaea97dbd8d73 to your computer and use it in GitHub Desktop.
获取 URL GET 参数
function getParam(paramName, defaultValue = '')
{
let url = location.search;
let params = new Object();
if (url.indexOf('?') != -1) {
url = url.slice(1);
strs = url.split('&');
strs.forEach(function (str) {
let keyValue = str.split('=');
params[keyValue[0]] = decodeURI(keyValue[1]);
});
}
return params[paramName] ? params[paramName] : defaultValue;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment