如何在JS中获得/之后的路径名



如果当前url为:"https://stackoverflow.com/questions/ask"

用什么方法来表达"questions/ask" ?

你可以使用

window.location.pathname.substring(1)

您将使用window.location.pathname

console.log(window.location.pathname.substring(1));

这将输出第一个/

之后的所有内容

最新更新