获取URL路径字符串中的最后一个值

Gro*_*ler 3 javascript url angularjs

鉴于href如下:

HTTP://本地主机:8888 /#/路/ someValue中/ needthis

如何获取路径字符串中的最后一个值(又名:"needthis")?

我尝试使用window.location.pathname,它给出了"/".

我也尝试过使用Angular $location,它没有提供最后一个值.

Dav*_*ama 11

你可以试试这个:

s="http://localhost:8888/#!/path/somevalue/needthis"
var final = s.substr(s.lastIndexOf('/') + 1);
alert(final)
Run Code Online (Sandbox Code Playgroud)