JavaScript

获取url传递的参数

2019-05-09  本文已影响1人  Lia代码猪崽

// 获取浏览器参数
function getRequest() {
//获取url中"?"符后的字串
const url = location.href
const theRequest = {}
const urlIndex = url.lastIndexOf('?')
if ( urlIndex !== -1 ) {
const str = url.substr(urlIndex + 1)
const strs = str.split('&')
for(let i = 0; i < strs.length; i++) {
theRequest[strs[i].split('=')[0]] = unescape(strs[i].split('=')[1])
}
}
return theRequest
}

上一篇 下一篇

猜你喜欢

热点阅读