【发布时间】:2018-03-02 06:43:35
【问题描述】:
我有 javascript 函数来映射 url 和超链接以突出显示菜单项,但是我不能在更深的页面中使用 url 最后一段带有数字,url 看起来像:http://localhost/story/89
如果最后一个 url 段是一个数字,我想删除它,因此该 url 将以 http://localhost/story 结尾(也删除 /)。
/* highlight nav menu */
$(function(){
$('#topMain li a').each(function(index) {
if($.trim(this.href) == stripQueryStringAndHashFromPath(window.location.href)) {
$(this).closest('li').addClass('active')
.closest('li.parent').addClass('active');
}
});
});
function stripQueryStringAndHashFromPath(url) {
return url.split("?")[0].split("#")[0];
}
【问题讨论】:
-
你这样做有什么意义?
标签: javascript url segment