Last active
March 20, 2019 08:57
-
-
Save codcodog/d2bbf0137eba9d45e82aaea97dbd8d73 to your computer and use it in GitHub Desktop.
获取 URL GET 参数
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
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