请编写一个JavaScript函数parseQueryString,他的用途是把URL参数解析为一个对象
var url = "https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd=nodemon&rsv_sug4=2634"; function parseQueryString(url){
var urlKey = url.split("?")[1]
var objKeyValue ={}
if(urlKey){
var urlObj = urlKey.split("&")
// 以对象形式存放
for(var i = 0; i<urlObj.length;i++){
objKeyValue[urlObj[i].split("=")[0]] = urlObj[i].split("=")[1]
}
return objKeyValue
}else{
return "暂无参数"
}
} var s = parseQueryString(url)
console.log(s)