【发布时间】:2017-05-11 13:11:16
【问题描述】:
我正在构建一个网页,当我浏览时不需要重新加载页面(我使用 ajax/php 来实现)。
当我浏览项目(很多)并打开其中一个时 - 我希望页面在我关闭页面时返回到页面的最后一个位置。
我使用锚来实现这一点。
我的代码:
$(document).on('click', '.content', function() {
... some other code ...
$.ajax({
type: 'POST',
url: '/includes/content.php',
data: info,
dataType: 'json',
success: function(result){
if(type == 'close') {
window.location.hash = '#' + hash;
location.reload();
}
}
});
return false;
});
问题是:jQuery 确实向 url 添加了一个哈希,但页面没有跳转到页面中的指定位置。 location.reload();确实这样做,但我不需要页面加载。
【问题讨论】:
-
请提供minimal reproducible example。浏览器控制台是否抛出任何错误?
-
缺失代码只是一堆变量集。
-
应该 window.location.hash = '#hash' 实际跳转到锚点还是只是在 url 中设置锚点?