Skip to content

Instantly share code, notes, and snippets.

@vace
Last active January 13, 2017 15:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vace/fd2fc67be0adb429f12d3c0d21d5047e to your computer and use it in GitHub Desktop.
Save vace/fd2fc67be0adb429f12d3c0d21d5047e to your computer and use it in GitHub Desktop.
格式化一个url中的参数
function parseUrlParam(url){
var match,
urlParams = {},
pl = /\+/g, // Regex for replacing addition symbol with a space
search = /([^&=]+)=?([^&]*)/g,
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); }
var query = url || location.href
var qus = query.indexOf('?')
if(qus !== -1){
query = query.substring(qus + 1)
}
var sup = query.indexOf('#')
if(sup !== -1){
query = query.substring(0,sup)
}
while (match = search.exec(query)){
urlParams[decode(match[1])] = decode(match[2]);
}
return urlParams
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment