1 回答

TA貢獻(xiàn)2003條經(jīng)驗 獲得超2個贊
您可以像這樣使用 localStorage 或 sessionStorage:在錨標(biāo)記所在的第一頁中
<a href="page.html" onclick="localStorage.setItem('anchor' , 'mydiv')"> Link</a>
在目標(biāo)頁面
<script>
$(function () {
// on document load
// if localStorage["anchor"] is set to a value
let target = localStorage.getItem("anchor");
if (target) {
// scroll to target
$('html, body').animate({ scrollTop: $(target).offset().top }, 'slow');
// clear localStorage
localStorage.removeItem("anchor");
}
});
</script>
- 1 回答
- 0 關(guān)注
- 185 瀏覽
添加回答
舉報