题解 | #数组求和#
获取 url 参数
http://www.nowcoder.com/practice/a3ded747e3884a3c86d09d88d1652e10
function getUrlParam(sUrl, sKey) {
var str = sUrl
var obj = {}
str.replace(/(\&{1}(\w+=\w+))|(\?\w+=\w+)/g, function (e1) {
//获取Key
var k = e1.substring(
1,
e1.indexOf('=')
)
//
var vl = e1.substring(e1.indexOf('=')+1, e1.length)
if (typeof obj[k] === 'string') {
obj[k] = [obj[k]]
obj[k].push(vl)
}
else if (obj[k] == undefined){
obj[k] = vl
}
else {
obj[k].push(vl)
}
})
if (sKey) {
return obj[sKey] ? obj[sKey] : ''
}
return obj
}