拉出部分页面URL
我的页面 URL 如下所示:
http://www.mydomain.com/directory/thisismy_page.html
使用 JavaScript,我想提取页面文件名中下划线之前的部分。所以在这个例子中,我想要:
thisismy
我目前有这个:
var filename = location.pathname.substring(location.pathname.lastIndexOf("/") + 1);
但这会拉出 thisismy_page.html
。如何在下划线处“停止”它,以便我得到的只是 thisismy
?
My page's URL is like this:
http://www.mydomain.com/directory/thisismy_page.html
Using JavaScript, I want to pull out the part of the page's filename before the underscore. So in this example, I want:
thisismy
I currently have this:
var filename = location.pathname.substring(location.pathname.lastIndexOf("/") + 1);
But that pulls out thisismy_page.html
. How do I "stop" it at the underscore so all I get is thisismy
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这会在下划线处将其拆分并获取第一个(或第 0 部分)。
This splits it at the underscore and takes the first (or 0th part).