【发布时间】:2012-03-01 01:23:38
【问题描述】:
我的页面网址是这样的:
http://www.mydomain.com/directory/thisismy_page.html
使用 JavaScript,我想提取页面文件名中下划线之前的部分。所以在这个例子中,我想要:
thisismy
我目前有这个:
var filename = location.pathname.substring(location.pathname.lastIndexOf("/") + 1);
但这会引出thisismy_page.html。如何在下划线处“停止”它,所以我得到的只是thisismy?
【问题讨论】:
标签: javascript url path location substring