我在使用插件的单页滚动模板中遇到问题(smoothscroll.js)我尝试在用户点击链接后从url中删除哈希但不幸的是我无法做到。我在stackoverflow上关注这类问题但不适合我。
我的代码如下:
指数:
<li><a href="#meet-us" class="page-scroll">Meet Us</a></li>
JS:
$('a.page-scroll').click(function (event) {
event.preventDefault();
if(history.pushState) {
history.pushState(null, null, $(this).attr('href'));
}
return false;
});
如何仅删除#
。现在是网址localhost/main/#meet-us
,但我需要localhost/main/meet-us
这种类型。
非常感谢,如果有人帮助的话。
答案 0 :(得分:2)
您可以使用String.prototype.replace:
history.pushState(null, null, $(this).attr('href').replace("#", ""));