如何获取不包含任何 URL 参数的 URL 段的最后一部分。
如果我在这个页面上:
http://example.com/myfolder/mypage.aspx?x=1
我想要得到:
mypage.aspx
最佳答案
你可以这样做:
// The first thing is to strip off the things after query string:
var url = "http://example.com/myfolder/mypage.aspx?x=1";
url = url.split("?")
url = url[0];
// Get the last path:
url = url.split("/");
page = url[url.length-1];
alert(page);
即使其中没有 ?
,上述路径也将起作用。
关于javascript - 在javascript中获取不带参数的url的最后一段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36570557/