js 获取浏览器地址栏网址 正则匹配需要的
1.获取完整的网址
window.location.href

2.获取域名以外的地址
window.location.pathname

3.获取域名 包括端口获取

window.location.hostname 一级域名获取

更多的直接看window.location

正则匹配需要的
想要的是匹配网址 /help/anzhuang/46.html 加粗的部分
获取地址栏参数
window.location.search

去除? 用replace 空字符串替换?实现 去掉?

得到的字符串进行字符串分组,根据&来分,用split
结果得到字符串数组

根据数组第一个元素(a[0]),继续分组
加粗为选择数组中需要的元素
window.location.search.replace("?","").split('&')[0].split('=')

数组取值 获取需要的
window.location.search.replace("?","").split('&')[0].split('=')[1]


浙公网安备 33010602011771号