Created
December 9, 2015 07:12
-
-
Save g8up/fe71b86a1bd7ce11b8e1 to your computer and use it in GitHub Desktop.
获取地址栏携带的参数
This file contains 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 parseParam( search ){ | |
var params = {}; | |
if( search.length > 2 ){ | |
if( search[0] === '?' ){ | |
var _search = search.slice(1); | |
var keyVals = _search.split('&'); | |
keyVals.forEach(function(pair){ | |
var kv = pair.split('='); | |
if( kv.length === 2 ){ | |
params[kv[0]] = kv[1]; | |
} | |
}); | |
} | |
} | |
return params; | |
} | |
function getParams(){ | |
var search = window.location.search; | |
console.log( parseParam( search ) ); | |
} | |
//# sourceURL=sigma.js | |
getParams() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment