Jquery:使用window.location获取特定的url路径
我们的 url 路径名是
www.nicadpower.com/index.com
,但我们只想获取 www.nicadpower.com 之后的路径名,这就是
index.com
我们如何使用 window.location 和 jquery 获取 index.com
Our url pathname is
www.nicadpower.com/index.com
but we only want to get the pathname after www.nicadpower.com which is
index.com
how can we get index.com using window.location and jquery
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想你想要
这会给你 /index.com
要摆脱前导 /,你可以简单地使用子字符串:
I think you want
This would give you /index.com
To get rid of the leading /, you could simply use substring:
这是您可以使用的另一个技巧。
您可以使用 split 方法拆分路径名部分,如下所示:
如果您有 url:
www.nicadpower.com/posts/2012
使用:
window.location.pathname.split('/ ')
您将给出:
["", "posts", "2012"]
Here is another trick that you can use.
You can split the pathname parts using split method, like that:
If you have the url:
www.nicadpower.com/posts/2012
Using:
window.location.pathname.split('/')
You'll Give:
["", "posts", "2012"]