// 获取url中query
// return {cate_id: '1', street_id: '0'}
function getParams() {
var url = location.search //获取url中"?"符后的字串
var theRequest = new Object()
if (url.indexOf("?") != -1) {
var str = url.substr(1)
strs = str.split("&")
for (var i = 0; i < strs.length; i++) {
theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1])
}
}
return theRequest
}
// 将json对象转成query字符串(不包含?)
// return cate_id=1&street_id=0
function parseParams(data) {
try {
var tempArr = []
for (var i in data) {
var key = encodeURIComponent(i)
var value = encodeURIComponent(data[i])
tempArr.push(key + '=' + value)
}
var urlParamsStr = tempArr.join('&')
return urlParamsStr
} catch (err) {
return ''
}
}
标签:tempArr,return,url,查询,strs,var,js,id
From: https://www.cnblogs.com/sunr/p/17137874.html