87,990
社区成员
发帖
与我相关
我的任务
分享var map = {
'/test/a' : 'a文字',
'/test/b' : 'b文字',
'/test/c' : 'c文字'
}
var url = location.href;
document.write(map[url]);
代码丢在B页面,访问/test/a时页面显示a文字,其他同理。
你的描述“当前URL+路径”没看懂,url里面已经包含了路径了。

var map = {
'xxx.sss.com/a' : 'a文字',
'xxx.sss.com/b' : 'b文字',
'xxx.sss.com/c' : 'c文字'
}
var host = location.hostname; // 获取域名
var pathArr = location.pathname;// 获取路径
自己拼接一下吧。把上面map的key值改成对应的就行