javascript
function urlParse (search) {
let index = search.lastIndexOf('?')
let url = search.substr(index) || window.location.search
let obj = {}
let reg = /[?&][^?&]+=[^?&]+/g
let arr = url.match(reg)
if (arr) {
arr.forEach((item) => {
let tempArr = item.substring(1).split('=')
let key = decodeURIComponent(tempArr[0])
let val = decodeURIComponent(tempArr[1])
obj[key] = val
})
}
return obj
}
// urlParse('https://www.baidu.com/index?a=1&b=3')
// {a: "1", b: "3"}
// urlParse()
// f:"8",ie:"utf-8",oq:"substr",rqlang:"cn",……}
1234567891011121314151617181920
评论 (0)