Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jquery:使用window.location获取特定url路径_Jquery_Jquery Selectors_Window.location - Fatal编程技术网

Jquery:使用window.location获取特定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); 这是你可以使用的另一个技巧。 您可以使用拆分方法

我们的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/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);