Jquery:使用window.location获取特定url路径
我们的url路径名是Jquery:使用window.location获取特定url路径,jquery,jquery-selectors,window.location,Jquery,Jquery Selectors,Window.location,我们的url路径名是 www.nicadpower.com/index.com 但是我们只想在www.nicadpower.com之后获得路径名,这是 我们如何使用window.location和jquery获取index.com?我想这是您想要的 window.location.pathname 这将为您提供/index.com 要去掉前导/,只需使用子字符串: window.location.pathname.substring(1); 这是你可以使用的另一个技巧。 您可以使用拆分方法
www.nicadpower.com/index.com
但是我们只想在www.nicadpower.com之后获得路径名,这是
我们如何使用window.location和jquery获取index.com?我想这是您想要的
window.location.pathname
这将为您提供/index.com
要去掉前导/,只需使用子字符串:
window.location.pathname.substring(1);
这是你可以使用的另一个技巧。 您可以使用拆分方法拆分路径名部分,如下所示: 如果你有网址:
www.nicadpower.com/posts/2012
使用:window.location.pathname.split('/')
您将给出:
[“”,“posts”,“2012”]
console.log(window.location.pathname.substring(1));把这个放在我的js上就意味着得到了www.nicadpower.com/index.phpthanks-ord!现在是好的。我只是在子字符串上添加了更多整数。谢谢!
window.location.pathname.substring(1);