js css html

获取路由中的值

2023-03-06  本文已影响0人  Amanda妍

获取浏览器地址栏的值
tool['getQueryValue'] = (queryName) => {
const reg = new RegExp('(^|&)' + queryName + '=([^&]*)(&|$)', 'i')
const r = window.location.search.substr(1).match(reg)
if (r != null) return decodeURI(r[2])
else return null
}

获取路由的值
tool['judgeParams'] = (url, param) => {
const reg = new RegExp('(^|&)' + param + '=([^&]*)(&|$)', 'i')
const index = url.lastIndexOf("?")
const r = url.substring(index + 1, url.length).match(reg)
if (r != null) return decodeURI(r[2])
else return null
}

上一篇下一篇

猜你喜欢

热点阅读